private bool TrySetOperationInternalWithProgress(AsyncProgressOperation op, string text, CancellationTokenSource canTokenSource) { var waitLoop = new HostWaitLoop(text); lock (_eventLock) { if (_isClosed) { throw new ObjectDisposedException("WorkerThread"); } if (_runningOp == null) { _runningOpCompleteEvent.Reset(); OperationDescriptor runningOp = new OperationDescriptor(new AsyncOperation(() => { return(op(waitLoop)); })); _runningOp = runningOp; _opSet.Set(); waitLoop.Wait(_runningOpCompleteEvent, canTokenSource); Debug.Assert(runningOp.IsComplete, "Why isn't the running op complete?"); if (runningOp.ExceptionDispatchInfo != null) { runningOp.ExceptionDispatchInfo.Throw(); } return(true); } } return(false); }
internal void SetOperationInternalWithProgress(AsyncProgressOperation op, string text, CancellationTokenSource canTokenSource) { // If this is called on the Worker thread it will deadlock Debug.Assert(!IsPollThread()); while (true) { if (_isClosed) { throw new ObjectDisposedException("WorkerThread"); } _runningOpCompleteEvent.WaitOne(); if (TrySetOperationInternalWithProgress(op, text, canTokenSource)) { return; } } }
public void RunOperation(string text, CancellationTokenSource canTokenSource, AsyncProgressOperation op) { if (op == null) { throw new ArgumentNullException(); } SetOperationInternalWithProgress(op, text, canTokenSource); }
private bool TrySetOperationInternalWithProgress(AsyncProgressOperation op, string text, CancellationTokenSource canTokenSource) { var waitLoop = new HostWaitLoop(text); lock (_eventLock) { if (_isClosed) throw new ObjectDisposedException("WorkerThread"); if (_runningOp == null) { _runningOpCompleteEvent.Reset(); OperationDescriptor runningOp = new OperationDescriptor(new AsyncOperation(() => { return op(waitLoop); })); _runningOp = runningOp; _opSet.Set(); waitLoop.Wait(_runningOpCompleteEvent, canTokenSource); Debug.Assert(runningOp.IsComplete, "Why isn't the running op complete?"); if (runningOp.ExceptionDispatchInfo != null) { runningOp.ExceptionDispatchInfo.Throw(); } return true; } } return false; }
internal void SetOperationInternalWithProgress(AsyncProgressOperation op, string text, CancellationTokenSource canTokenSource) { // If this is called on the Worker thread it will deadlock Debug.Assert(!IsPollThread()); while (true) { if (_isClosed) throw new ObjectDisposedException("WorkerThread"); _runningOpCompleteEvent.WaitOne(); if (TrySetOperationInternalWithProgress(op, text, canTokenSource)) { return; } } }
public void RunOperation(string text, CancellationTokenSource canTokenSource, AsyncProgressOperation op) { if (op == null) throw new ArgumentNullException(); SetOperationInternalWithProgress(op, text, canTokenSource); }