public void AddTask(ZAwsTask newTask) { lock (myLock) { newTask.SetQueue(this); myTaskList.Add(newTask); runnerEver.Set(); } }
internal ZAwsTaskHandler(ZAwsEc2Controller controller) { myController = controller; handlerThread = new Thread(new ThreadStart(delegate { Thread.CurrentThread.Name = "TaskHandler"; while (runner) { ZAwsObject currentObject = null; lock (myLock) { try { currentObject = myTagetObjects.Dequeue(); } catch (System.InvalidOperationException) { if (!runner) { return; } runnerEver.Reset(); } } if (currentObject == null) { //Now wait for the next object to be added runnerEver.WaitOne(3000); continue; } while (true) { ZAwsTask currentTask = null; lock (myLock) { for (int i = 0; i < myTaskList.Count; i++) { if (myTaskList[i].WillHandle(currentObject)) { //remove this task from list currentTask = myTaskList[i]; myTaskList.RemoveAt(i); break; } } } if (currentTask == null) { break; } if (sleepEvent.WaitOne(currentTask.DelayBeforeTaskStart * 1000)) { //This event is only set by the Close function, so if this returns true, you should close right away return; } Program.TraceLine(currentTask.StartMessage); try { currentTask.DoExecute(currentObject); Program.TraceLine(currentTask.SuccessMessage); } catch (Exception ex) { Program.TraceLine(currentTask.ExceptionMessage, ex); } } } })); handlerThread.Start(); }