Пример #1
0
        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);
            }
        }
Пример #2
0
        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;
            }
        }