start processes with a delay

后端 未结 1 781
你的背包
你的背包 2021-01-27 21:41

How can I start 5 different processes, each with their own delay without holding up the other ones while waiting for the delay to finish? I can not use async or await

         


        
相关标签:
1条回答
  • 2021-01-27 22:19

    You could start every process from a different thread.

    foreach (string process1 in _processList)
    {
      Thread t = new Thread(() => 
               {
                   Thread.Sleep(/*RANDOM NUMBER*/ 5);
                   Process.Start(process1);
               });
      t.Start();
    }
    

    That way each process will have a random timer before it start and no process is delayed for the start of an other process.

    If starting thread is totaly impossible in your situation, i would suggest wrapping your process to a .bat and in this batch file you add the sleep delay this way all the process will be called in time and the sleep delay will be respected.

    0 讨论(0)
提交回复
热议问题