/// <summary> /// Disposes all dispatcher resources and remaining tasks. /// </summary> public override void Dispose() { while (true) { lock (TaskListSyncRoot) { if (TaskList.Count != 0) { _currentTask = TaskList.Dequeue(); } else { break; } } _currentTask.Dispose(); } DataEvent.Close(); DataEvent = null; if (CurrentDispatcher == this) { CurrentDispatcher = null; } if (MainDispatcher == this) { MainDispatcher = null; } }
public override void Dispose() { base.Dispose(); if (Dispatcher != null) { Dispatcher.Dispose(); } Dispatcher = null; }
/// <summary> /// Initializes a new instance of the <see cref="CustomThread" /> class. /// </summary> /// <param name="threadName">Name of the thread.</param> /// <param name="targetDispatcher">The target dispatcher.</param> /// <param name="autoStartThread">if set to <c>true</c> [automatic start thread].</param> protected CustomThread(string threadName, CustomTaskDispatcher targetDispatcher, bool autoStartThread) { _threadName = threadName; TargetDispatcher = targetDispatcher; if (autoStartThread) { Start(); } }
/// <summary> /// Creates a Dispatcher, if a Dispatcher has been created when setThreadDefaults is set to true in the current thread /// an exception will be thrown. /// </summary> /// <param name="setThreadDefaults">If set to true the new dispatcher will be set as threads default dispatcher.</param> public CustomTaskDispatcher(bool setThreadDefaults) { if (!setThreadDefaults) { return; } if (CurrentDispatcher != null) { throw new InvalidOperationException("Only one Dispatcher instance allowed per thread."); } CurrentDispatcher = this; if (MainDispatcher == null) { MainDispatcher = this; } }
/// <summary> /// Initializes a new instance of the <see cref="CustomThread" /> class. /// </summary> /// <param name="threadName">Name of the thread.</param> /// <param name="targetDispatcher">The target dispatcher.</param> protected CustomThread(string threadName, CustomTaskDispatcher targetDispatcher) : this(threadName, targetDispatcher, true) { }
public TaskWorker(string name, TaskDistributor taskDistributor) : base(name, false) { TaskDistributor = taskDistributor; Dispatcher = new CustomTaskDispatcher(false); }
/// <summary> /// Fills the tasks. /// </summary> /// <param name="target">The target.</param> internal void FillTasks(CustomTaskDispatcher target) { target.AddTasks(IsolateTasks(1)); }