Beispiel #1
0
 public void Dispose()
 {
     StopAsync();
     ClearJob();
     IsFault    = false;
     ownedJob   = null;
     CallerInfo = null;
 }
Beispiel #2
0
 public void Dispose()
 {
     if (!RunningDisposeAfterFinish)
     {
         StopAsync();
     }
     ClearJob();
     IsFault    = false;
     ownedJob   = null;
     CallerInfo = null;
 }
Beispiel #3
0
 /// <summary>
 /// add additional job into running thread
 /// </summary>
 /// <param name="l">an action job which contains statements for running</param>
 public void AddAfterFinishJob(Control c, Action <AsyncTask> l,
                               [CallerMemberName] string memberName    = "",
                               [CallerFilePath] string sourceFilePath  = "",
                               [CallerLineNumber] int sourceLineNumber = 0)
 {
     lock (AfterFinishJobLocker)
     {
         CallerInfoClazz info = new CallerInfoClazz()
         {
             Line = sourceLineNumber, MemberName = memberName, SourceCode = sourceFilePath
         };
         AfterFinishJob.AddLast(new AfterFinishJobArgs()
         {
             Ctrl = c, Action = l, callerInfo = info
         });
     }
 }
Beispiel #4
0
        private bool PollAndRunJobAfterFinishJob()
        {
            object          job        = null;
            Control         ctrl       = null;
            CallerInfoClazz callerInfo = null;

            lock (AfterFinishJobLocker)
            {
                if (AfterFinishJob.Count > 0)
                {
                    job        = AfterFinishJob.First.Value.Action;
                    ctrl       = AfterFinishJob.First.Value.Ctrl;
                    callerInfo = AfterFinishJob.First.Value.callerInfo;
                    AfterFinishJob.RemoveFirst();
                }
            }

            return(ControlInvoker(ctrl, job, callerInfo));
        }
Beispiel #5
0
 private bool ControlInvoker(Control ctrl, object job, CallerInfoClazz info = null)
 {
     if (job != null)
     {
         try
         {
             if (this.CallerInfo != null)
             {
                 this.CallerInfo = info;
             }
             if (job is Action)
             {
                 Action       actionObj = (Action)job;
                 EventHandler Invoker   = null;
                 Invoker = new EventHandler((object sender, EventArgs args) =>
                 {
                     if (sender is Control)
                     {
                         (sender as Control).HandleCreated -= Invoker;
                     }
                     ctrl.Invoke(actionObj);
                 });
                 if (ctrl != null)
                 {
                     if (ctrl.IsHandleCreated && !ctrl.IsDisposed)
                     {
                         ctrl.Invoke(actionObj);
                     }
                     else if (!ctrl.IsHandleCreated)
                     {
                         ctrl.HandleCreated += Invoker;
                     }
                 }
                 else
                 {
                     actionObj();
                 }
             }
             else if (job is Action <AsyncTask> )
             {
                 Action <AsyncTask> asyncJob = (Action <AsyncTask>)job;
                 EventHandler       Invoker  = null;
                 Invoker = new EventHandler((object sender, EventArgs args) =>
                 {
                     if (sender is Control)
                     {
                         (sender as Control).HandleCreated -= Invoker;
                     }
                     ctrl.Invoke(asyncJob, this);
                 });
                 if (ctrl != null)
                 {
                     if (ctrl.IsHandleCreated && !ctrl.IsDisposed)
                     {
                         ctrl.Invoke(asyncJob, this);
                     }
                     else if (!ctrl.IsHandleCreated)
                     {
                         ctrl.HandleCreated += Invoker;
                     }
                 }
                 else
                 {
                     asyncJob(this);
                 }
             }
         }
         catch (Exception ee)
         {
             Console.WriteLine(ee.ToString());
         }
         return(true);
     }
     return(false);
 }