// ==================================================================== void WorkingThread() { while (!_stop) { if (_stop) { break; } TaskInfo task = null; lock (_syncRoot) { if (_queue.Count != 0) { task = _queue.Dequeue(); } } if (task == null) { _event.WaitOne(); } else { try { try { _executing = true; task.Action(task.Data); } finally { _executing = false; _event.Set(); } } catch (Exception ex) { // IrbisProxy.WriteException(ex); Debug.WriteLine(ex); } } } }
private void ExecuteTask(TaskInfo task, object param) { Debug.Assert(task != null); try { task.Action(param); } catch (Exception ex) { Logger.Exception(ex); if (OnException != null) { try { OnException(this, new TaskExceptionArgs(task.Name, param, ex)); } catch (Exception) { } } } finally { task.LastEndTime = DateTime.Now; } }
/// <summary> /// Выполнение заданий. /// </summary> /// <param name="arg">Данные для обработки.</param> private void _WorkerMethod ( object arg ) { try { TaskInfo taskInfo = (TaskInfo)arg; taskInfo.Action(taskInfo.Data); } finally { lock ( _syncRoot ) { if (_workersActive > 0) { _workersActive--; } _flagEvent.Set(); } } }