Exemplo n.º 1
0
 public void Dispose()
 {
     StopAsync();
     ClearJob();
     IsFault    = false;
     ownedJob   = null;
     CallerInfo = null;
 }
Exemplo n.º 2
0
 public void Dispose()
 {
     if (!RunningDisposeAfterFinish)
     {
         StopAsync();
     }
     ClearJob();
     IsFault    = false;
     ownedJob   = null;
     CallerInfo = null;
 }
Exemplo n.º 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
         });
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
 }