自动代理切换器WInform(C#)

问题描述 投票:-1回答:1

我是C#的新手,我正在尝试使用它构建一个应用程序。

在我的应用程序中,可以选择在Web浏览器上使用代理。我已经找到了在Web浏览器上使用代理的方法。工作原理:用户粘贴单个IP:端口代理,点击开始按钮后,应用程序会通知Web浏览器使用指定的代理服务器。

!问题:问题是我希望应用程序在一段时间后切换代理。

我的概念是:用户可以粘贴代理列表的textbox,在用户点击开始按钮后,应用程序将告诉Web浏览器在第一行使用代理。

在(比方说)30秒后,它将自动切换到第二行,依此类推,直到用户点击停止按钮。

基本上,它将在一定时间后垂直切换到新线。

谢谢。

c# winforms
1个回答
0
投票
  1. 添加计时器控件。

请参阅以下代码

List<string> lstIpAddress = new List<string>();
int nCount = 0;

private void Form1_Load(object sender, EventArgs e)
{
   timer1.Interval = 30000;
}

 private void button1_Click(object sender, EventArgs e)
 {
        string strIp = textBox1.Text;
        if (strIp.Length > 0)
        {
            lstIpAddress = strIp.Split(',').ToList();
            for (int nlstItem = 0; nlstItem < lstIpAddress.Count; nlstItem++)
            {
                listBox1.Items.Add(lstIpAddress[nlstItem]);
            }
            //Pass the IP to Web Browser
            label2.Text = listBox1.Items[nCount].ToString();
            nCount++;
        }
        timer1.Start();
 }

 private void timer1_Tick(object sender, EventArgs e)
 {
        timer1.Stop();
        //Pass the IP to Web Browser
        label2.Text = listBox1.Items[nCount].ToString();
        timer1.Start();
 }

IP Address

© www.soinside.com 2019 - 2024. All rights reserved.