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);
            }
        }
        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;

                    CreateSyntaxTree(snapshot, cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();

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

                    if (TryCreateSemanticModel(snapshot, cancellationToken))
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        RaiseEvent(SemanticModelAvailable, args);
                    }
                }
                catch (OperationCanceledException)
                {
                }

                Thread.Yield();
            }
        }