protected override void Dispose(bool disposing) { if (disposing) { Task DisposeAction() => Task.Factory.StartNew(() => { Trace.WriteLine("Running dispose task"); SchedulerRunCancellationTokenSource.Cancel(); }, CancellationToken.None, TaskCreationOptions.None, ProxyScheduler.AsTplScheduler()); var disposeTask = postToScheduler(DisposeAction); disposeTask.Wait(); m_postOnCallStack.Dispose(); } }
protected override void Dispose(bool disposing) { try { m_ignoreCancellationToken.Value = true; SchedulerRunCancellationTokenSource.Cancel(); QueueTasksResult result; do { result = QueueTasksToInnerScheduler(); result.WhenAllTask.Wait(); } while (result.HasMoreTasks); } finally { m_ignoreCancellationToken.Value = false; } m_ignoreCancellationToken.Dispose(); }
public void Dispose() { lock (m_serviceLockObject) { if (m_disposed) { return; } try { Dispose(true); m_disposed = true; m_serviceCompleteTcs.TrySetResult(null); SchedulerRunCancellationTokenSource.Cancel(); } catch (Exception ex) { Trace.WriteLine(ex); m_serviceCompleteTcs.TrySetException(ex); } } }