Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
                }
            }
        }
Exemplo n.º 3
0
        public void RunOperation(string text, CancellationTokenSource canTokenSource, AsyncProgressOperation op)
        {
            if (op == null)
            {
                throw new ArgumentNullException();
            }

            SetOperationInternalWithProgress(op, text, canTokenSource);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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;
                }
            }
        }
Exemplo n.º 6
0
        public void RunOperation(string text, CancellationTokenSource canTokenSource, AsyncProgressOperation op)
        {
            if (op == null)
                throw new ArgumentNullException();

            SetOperationInternalWithProgress(op, text, canTokenSource);
        }