Exemplo n.º 1
0
        /// <summary>
        /// 异步工作已完成的回调方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RunWorkerCompletedAdapter(object sender, RunWorkerCompletedEventArgs e)
        {
            T data = default(T);

            if (!e.Cancelled && e.Error == null && e.Result != null)
            {
                data = (T)e.Result; // worker result is our data
            }

            if (this.WorkerMethodCompletedCallback != null)
            {
                AsyncWorkerCallbackEventArgs <T> args = new AsyncWorkerCallbackEventArgs <T>(handle, data, e.Error);
                WorkerMethodCompletedCallback(this, args);
            }

            ResetTimeoutTimer();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 异步工作方法超时计时器回调方法
        /// </summary>
        /// <param name="state"></param>
        private void OnTimeoutTimerCallback(object state)
        {
            BackgroundWorker backgroundWorker = state as BackgroundWorker;

            if (backgroundWorker != null)
            {
                backgroundWorker.CancelAsync();
            }

            if (this.WorkerMethodCompletedCallback != null)
            {
                AsyncWorkerCallbackEventArgs <T> args = new AsyncWorkerCallbackEventArgs <T>(
                    handle, default(T),
                    new TimeoutException(string.Format(CultureInfo.InvariantCulture,
                                                       @"Asynchronous worker [{0}] is timeout.", this.WorkerMethod.Method.Name)));
                WorkerMethodCompletedCallback(this, args);
            }

            ResetTimeoutTimer();
        }