private void OnTerminate(object sender, EventArgs e) { AssertIsMainThread(); // Don't let the app teminate while the background thread is doing work if (_taskDoneEvent != null) { _taskDoneEvent.WaitOne(); } Dispose(); }