public static BackgroundParserTask CreateAndStart(RazorEditorParser parser, TextChange change, Block parseTree) { CancellationTokenSource cancelSource = new CancellationTokenSource(); BackgroundParserTask task = new BackgroundParserTask() { CancelSource = cancelSource }; CancellationToken token = cancelSource.Token; task.Task = Task.Factory.StartNew(() => { try { Interlocked.Increment(ref _activeTaskCount); parser.ProcessChange(token, change, parseTree); } catch (OperationCanceledException) { } #if DEBUG catch (Exception ex) { if (Debugger.IsAttached) { throw; } Debug.Fail("Unexpected exception thrown by parser task", ex.ToString()); } #else catch (Exception) { } #endif }, token); return(task); }
protected internal virtual void QueueFullReparse(TextChange change) { if (_currentTask != null) { _currentTask.Dispose(); } _currentTask = BackgroundParserTask.CreateAndStart(this, change, _currentParseTree); }
public static BackgroundParserTask CreateAndStart(RazorEditorParser parser, TextChange change, Block parseTree) { CancellationTokenSource cancelSource = new CancellationTokenSource(); BackgroundParserTask task = new BackgroundParserTask() { CancelSource = cancelSource }; CancellationToken token = cancelSource.Token; task.Task = Task.Factory.StartNew(() => { try { Interlocked.Increment(ref _activeTaskCount); parser.ProcessChange(token, change, parseTree); } catch (OperationCanceledException) { } #if DEBUG catch (Exception ex) { if (Debugger.IsAttached) { throw; } Debug.Fail("Unexpected exception thrown by parser task", ex.ToString()); } #else catch (Exception) { } #endif }, token); return task; }