Trying to write a planner. It is necessary that the two threads ( LoopGetTask and LoopExecTask ) run in parallel, but Thread.Sleep does not give the desired result (only one of the functions is executed). The impression is that Thread.Sleep affects both threads no matter where it is called
public class Scheduler { private Thread ThrExecTask; private Thread ThrGetTask; private Queue<int> taskList = new Queue<int>(); public Scheduler() { work = false; ThrExecTask = new Thread(LoopExecTask); ThrGetTask = new Thread(LoopGetTask); ThrExecTask.Start(); ThrGetTask.Start(); } } private void LoopGetTask() { while(true) { //получить список задач... insert into taskList Thread.Sleep(20000); } } private void LoopExecTask() { while(true) { //выполнить задачу exec taskList.first Thread.Sleep(1000); } } }