So first here is some pseudo code of what I want to improve.
public List<ProcessData> Processes; System.Threading.Thread ProcessThread; void ProcessLoop() { while (true) { for (int i = 0; i < Processes.Count; i++) { if (HasPriority(Processes[i])) { Process(Processes[i]); } } System.Threading.Thread.Sleep(1000); } } void AddProcessData(ProcessData pd) { Processes.Add(pd); if (Suspended(ProcessThread)) Resume(ProcessThread); } void Startup() { ProcessThread = new System.Threading.Thread(ProcessLoop); ProcessThread.Start(); }
So what I want to do is replace the 'Sleep' with code that will suspend the thread or have it wait until something is added to the list and then resume it. I also need it to be thread safe of course.