private void DoTask(QueueTask task) { string taskname = null; bool exception = false; try { taskname = task.Action.Method.Name; task.Action(); } catch (Exception e) { exception = true; if (task.OnException != null) { SubThreadChanger.InvokeInLocalThread(() => task.OnException(e)); } else { Logger.Log(LogLevel.Error, e, "Async task failed, with Exception"); throw; } } Logger.Log(LogLevel.Debug, "Async task finished : {0}", taskname); if (task.OnTaskTermination != null && !exception) { SubThreadChanger.InvokeInLocalThread(task.OnTaskTermination); } }
public void Dispose() { if (!_disposed) { if (ForceDispose) { _tasks.Clear(); } EnqueueTask(null); // null will signal the consumer to exit. // Wait for the thread to Stop while (!_worker.Join(100)) { SubThreadChanger.PumpMessages(100, Logger); } _wh.Close(); // Release any OS resources. _disposed = true; } }