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(); } }
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(); } }
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 RaiseEvent(EventHandler<BackgroundParserEventArgs> handler, BackgroundParserEventArgs args) { if (handler == null) return; foreach (EventHandler<BackgroundParserEventArgs> h in handler.GetInvocationList()) { args.CancellationToken.ThrowIfCancellationRequested(); h(this, args); } }