예제 #1
0
        /// <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;
            }
        }
예제 #2
0
파일: TaskWorker.cs 프로젝트: supermax/TMS
 public override void Dispose()
 {
     base.Dispose();
     if (Dispatcher != null)
     {
         Dispatcher.Dispose();
     }
     Dispatcher = null;
 }
예제 #3
0
        /// <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();
            }
        }
예제 #4
0
        /// <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;
            }
        }
예제 #5
0
 /// <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)
 {
 }
예제 #6
0
파일: TaskWorker.cs 프로젝트: supermax/TMS
 public TaskWorker(string name, TaskDistributor taskDistributor)
     : base(name, false)
 {
     TaskDistributor = taskDistributor;
     Dispatcher      = new CustomTaskDispatcher(false);
 }
예제 #7
0
 /// <summary>
 /// Fills the tasks.
 /// </summary>
 /// <param name="target">The target.</param>
 internal void FillTasks(CustomTaskDispatcher target)
 {
     target.AddTasks(IsolateTasks(1));
 }