private void ProcessingComplete(object sender, RunWorkerCompletedEventArgs e) { BackgroundWorker.DoWork -= _lastTask; IsProcessing = false; if (PostWorkEvent != null) { PostWorkEvent(e.Result); PostWorkEvent = null; } }
/// <summary> Executes the background function operation. </summary> /// <param name="task"> The task. </param> /// <param name="postWorkEvent"> The post work event. </param> public void RunBackgroundFunction(DoWorkEventHandler task, PostWorkEventDelegate postWorkEvent = null) { if (IsProcessing) { return; } _lastTask = task; PostWorkEvent = postWorkEvent; IsProcessing = true; BackgroundWorker.DoWork += task; BackgroundWorker.RunWorkerAsync(); }