예제 #1
0
        private void DoWork()
        {
            while (!_shutdownToken.IsCancellationRequested)
            {
                try
                {
                    _hasWork.Wait(_shutdownToken.Token);
                }
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (ObjectDisposedException)
                {
                    return;
                }
                _hasWork.Reset();

                lock (_lockObject)
                {
                    _currentParseCancellationTokenSource = new CancellationTokenSource();
                }

                var snapshot = _textBuffer.CurrentSnapshot;

                try
                {
                    var cancellationToken = _currentParseCancellationTokenSource.Token;

                    // Force creation of SyntaxTree.
                    snapshot.GetSyntaxTree(cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();

                    var args = new BackgroundParserEventArgs(snapshot, cancellationToken);
                    RaiseEvent(SyntaxTreeAvailable, args);

                    // Force creation of SemanticModel.
                    SemanticModel semanticModel;
                    if (snapshot.TryGetSemanticModel(cancellationToken, out semanticModel))
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        RaiseEvent(SemanticModelAvailable, args);
                    }
                }
                catch (OperationCanceledException)
                {

                }

                Thread.Yield();
            }
        }
예제 #2
0
        private void DoWork()
        {
            while (!_shutdownToken.IsCancellationRequested)
            {
                try
                {
                    _hasWork.Wait(_shutdownToken.Token);
                }
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (ObjectDisposedException)
                {
                    return;
                }
                _hasWork.Reset();

                lock (_lockObject)
                {
                    _currentParseCancellationTokenSource = new CancellationTokenSource();
                }

                var snapshot = _textBuffer.CurrentSnapshot;

                try
                {
                    var cancellationToken = _currentParseCancellationTokenSource.Token;

                    // Force creation of SyntaxTree.
                    snapshot.GetSyntaxTree(cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();

                    var args = new BackgroundParserEventArgs(snapshot, cancellationToken);
                    RaiseEvent(SyntaxTreeAvailable, args);

                    // Force creation of SemanticModel.
                    SemanticModel semanticModel;
                    if (snapshot.TryGetSemanticModel(cancellationToken, out semanticModel))
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        RaiseEvent(SemanticModelAvailable, args);
                    }
                }
                catch (OperationCanceledException)
                {
                }

                Thread.Yield();
            }
        }
예제 #3
0
        private void RaiseEvent(EventHandler <BackgroundParserEventArgs> handler, BackgroundParserEventArgs args)
        {
            if (handler == null)
            {
                return;
            }

            foreach (EventHandler <BackgroundParserEventArgs> h in handler.GetInvocationList())
            {
                args.CancellationToken.ThrowIfCancellationRequested();
                h(this, args);
            }
        }
예제 #4
0
        private void RaiseEvent(EventHandler<BackgroundParserEventArgs> handler, BackgroundParserEventArgs args)
        {
            if (handler == null)
                return;

            foreach (EventHandler<BackgroundParserEventArgs> h in handler.GetInvocationList())
            {
                args.CancellationToken.ThrowIfCancellationRequested();
                h(this, args);
            }
        }