public void Run() { var previousContext = SynchronizationContext.Current; try { singleContext = new SingleContext(); SynchronizationContext.SetSynchronizationContext(singleContext); var execution = Start(); execution.ContinueWith(delegate { singleContext.Complete(); }, TaskScheduler.Default); singleContext.Run(); execution.Wait(); } finally { SynchronizationContext.SetSynchronizationContext(previousContext); } }
public void Stop() { running = false; singleContext.Complete(); }