public static async void Execute()
{
while (true)
{
while (_saveJobQueue != null && _saveJobQueue.Count > 0)
{
SaveJob actualJob;
lock (QueueLock)
{
actualJob = _saveJobQueue.Dequeue();
}
try
{
await actualJob.ProgramToSave.Save();
}
catch(Exception e)
{
Debug.WriteLine("Could not Save, Exception: " + e.Message);
continue;
}
}
// To ensure that the thread will do all savejobs left before stopping
if (!running)
break;
waitHandle.WaitOne();
waitHandle.Reset();
}
}