コード例 #1
0
        /// <summary>
        /// Sub called by the worker to signal the end of the work
        /// </summary>
        /// <param name="result">
        /// Worker result
        /// </param>
        /// <remarks></remarks>
        internal void WorkerDoneInternalSignal(TResultType result)
        {
            if (_isAsynchonous && (_workerThread != null))
            {
                _workerThread.Join();
                _workerThread = null;
            }

            //Check if the results/exception have already been processed (because the owner was waiting for the worker to end)
            if (!_cancelWorkerDoneEvent)
            {
                //Prepare and raise the event for the owner to process
                var e = new WorkerDoneEventArgs <TResultType>(Identity, result, _worker.InterruptionRequested);

                if (WorkerDone != null)
                {
                    WorkerDone(this, e);
                }
            }

            //If the worker was running in asynchronous mode, we also need to post the "complete" message
            if (_isAsynchonous)
            {
                _callingThreadAsyncOp.PostOperationCompleted(DoNothing, null);
            }
        }
コード例 #2
0
        private void asyncManager_WorkerDone(object sender, WorkerDoneEventArgs <object> e)
        {
            if (m_workDone != null)
            {
                m_workDone(e.Result);

                if (e.Exception != null)
                {
                    ExceptionProcess.ProcessWithNotify(e.Exception);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Abort
        /// </summary>
        /// <returns></returns>
        public WorkerDoneEventArgs <TResultType> AbortWorker()
        {
            WorkerDoneEventArgs <TResultType> result = new WorkerDoneEventArgs <TResultType>(Identity, null, true);

            if (((_workerThread != null)) && _workerThread.IsAlive)
            {
                _workerThread.Abort();
                //result = WaitForWorker();
                _workerThread = null;
            }
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Called from the owner to stop and wait for the worker
        /// </summary>
        /// <remarks></remarks>
        public WorkerDoneEventArgs <TResultType> StopWorkerAndWait()
        {
            WorkerDoneEventArgs <TResultType> result = null;

            if (((_workerThread != null)) && _workerThread.IsAlive)
            {
                StopWorker();

                result = WaitForWorker();
            }

            return(result);
        }