Exemple #1
0
        private void OnWork(object Argument)
        {
            ThreadCompleteEventArgs completeArgs = new ThreadCompleteEventArgs();

            try
            {
                lock (locker)
                {
                    workArgs.Clear();
                    workArgs.Argument     = Argument;
                    completeArgs.Argument = Argument;
                    IsWork = true;
                    startHandle.Set();
                }
                Work(this, workArgs);
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }
            catch (ThreadInterruptedException)
            {
            }
            catch (Exception ex)
            {
                completeArgs.Error = ex;
            }
            finally
            {
                IsWork = false;
                stopHandle.Set();

                //lock (locker)
                {
                    completeArgs.IsCanceled = workArgs.Cancel;
                    completeArgs.IsAborted  = workArgs.Abort;
                    completeArgs.Result     = workArgs.Result;
                }

                completeHandle.Set();
                thread = null;

                OnComplete(completeArgs);

                //if (completeArgs.Restart)
                //{
                //    if (Argument != null)
                //        Run(Argument);
                //    else
                //        Run();
                //}
            }
        }
Exemple #2
0
 private void OnComplete(ThreadCompleteEventArgs args)
 {
     if (Complete == null)
     {
         return;
     }
     try
     {
         SendEvent(Complete.GetInvocationList(), new object[] { this, args });
     }
     catch
     {
     }
 }