/// <summary> /// /// </summary> /// <param name="workMethod"></param> /// <param name="workCompletedMethod"></param> protected void DoWorkAsync(WorkMethod workMethod, WorkCompletedMethod workCompletedMethod) { externalCompletedMethod = workCompletedMethod; if (IsAsync) { MakeBusy(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(workMethod); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnWorkerCompleted); worker.RunWorkerAsync(); } else { DoWorkEventArgs args = new DoWorkEventArgs(null); workMethod.Invoke(null, args); RunWorkerCompletedEventArgs completedArgs = new RunWorkerCompletedEventArgs(args.Result, null, args.Cancel); externalCompletedMethod.Invoke(null, completedArgs); } }
public void InvokeAsync(WorkMethod methodToInvoke, WorkCompletedMethod callbackMethod) { this.DoWorkAsync((s, args) => { methodToInvoke.Invoke(s, args); }, callbackMethod); }