简体   繁体   中英

Command prompt should open one window close after 5 seconds and reopen

So what happens is it opens a command prompt with the command then it opens a second command prompt after 5 seconds and then closes second window after 5 more seconds and opens a second window again leaving 1st window still open. I need it to close the first window every 5 seconds and reopen it so theres only one window active not two. I can't have 2 windows open because im trying to open a proxy with the command and if the proxy is open on 1st command window itll stay the same and not connect on the second.

    Thread thread1;
    private void Button1_Click(object sender, EventArgs e)
    {
        thread1 = new Thread(new ThreadStart(DoWork));
        thread1.Start();
    }


    public void DoWork()
    {
        bool run = true;
        while (run)
        {
            var lines = File.ReadAllLines(@"C:\Users\admin\source\repos\proxy\proxy\bin\Debug\proxies.txt");
            var r = new Random();
            var randomLineNumber = r.Next(0, lines.Length - 1);
            var line2 = lines[randomLineNumber];

            string line3 = line2.Replace(line2.Before(":") + ":", "");
            line3 = line3.Replace(":" + line2.After(":"), "");
            string strCmdText;
            strCmdText = "/K proxy-login-automator -local_port 8082 -remote_host zproxy.lum-superproxy.io -remote_port 22225 -usr " + line3.After(":") + " -pwd proxypw & pause";
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;
            startInfo.UseShellExecute = true;
            startInfo.FileName = "CMD.exe";
            startInfo.WorkingDirectory = @"C:\Users\admin\source\repos\proxy\proxy\bin\Debug";
            startInfo.WindowStyle = ProcessWindowStyle.Normal;
            startInfo.Arguments = strCmdText;
            using (Process exeProcess = Process.Start(startInfo))
            {
                Thread.Sleep(5000);
                exeProcess.Kill();
            }
        }

Windows have program name

Task Scheduler

, you can put your program in there and set occur every 5 seconds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM