private void CommitCore(IWaitContext waitContext, bool previewChanges) { var eventName = previewChanges ? FunctionId.Rename_CommitCoreWithPreview : FunctionId.Rename_CommitCore; using ( Logger.LogBlock( eventName, KeyValueLogMessage.Create(LogType.UserAction), waitContext.CancellationToken ) ) { var newSolution = _conflictResolutionTask.Join(waitContext.CancellationToken).NewSolution; waitContext.AllowCancel = false; if (previewChanges) { var previewService = _workspace.Services.GetService <IPreviewDialogService>(); newSolution = previewService.PreviewChanges( string.Format( EditorFeaturesResources.Preview_Changes_0, EditorFeaturesResources.Rename ), "vs.csharp.refactoring.rename", string.Format( EditorFeaturesResources.Rename_0_to_1_colon, this.OriginalSymbolName, this.ReplacementText ), _renameInfo.FullDisplayName, _renameInfo.Glyph, newSolution, _triggerDocument.Project.Solution ); if (newSolution == null) { // User clicked cancel. return; } } // The user hasn't cancelled by now, so we're done waiting for them. Off to // rename! waitContext.Message = EditorFeaturesResources.Updating_files; Dismiss(rollbackTemporaryEdits: true); CancelAllOpenDocumentTrackingTasks(); ApplyRename(newSolution, waitContext); LogRenameSession(RenameLogMessage.UserActionOutcome.Committed, previewChanges); EndRenameSession(); } }
private void CommitCore(IUIThreadOperationContext operationContext, bool previewChanges) { var eventName = previewChanges ? FunctionId.Rename_CommitCoreWithPreview : FunctionId.Rename_CommitCore; using (Logger.LogBlock(eventName, KeyValueLogMessage.Create(LogType.UserAction), operationContext.UserCancellationToken)) { var newSolution = _conflictResolutionTask.Join(operationContext.UserCancellationToken).NewSolution; if (previewChanges) { var previewService = _workspace.Services.GetService <IPreviewDialogService>(); operationContext.TakeOwnership(); newSolution = previewService.PreviewChanges( string.Format(EditorFeaturesResources.Preview_Changes_0, EditorFeaturesResources.Rename), "vs.csharp.refactoring.rename", string.Format(EditorFeaturesResources.Rename_0_to_1_colon, this.OriginalSymbolName, this.ReplacementText), _renameInfo.FullDisplayName, _renameInfo.Glyph, newSolution, _triggerDocument.Project.Solution); if (newSolution == null) { // User clicked cancel. return; } } // The user hasn't cancelled by now, so we're done waiting for them. Off to // rename! using var _ = operationContext.AddScope(allowCancellation: false, EditorFeaturesResources.Updating_files); Dismiss(rollbackTemporaryEdits: true); CancelAllOpenDocumentTrackingTasks(); _triggerView.Caret.PositionChanged += LogPositionChanged; ApplyRename(newSolution, operationContext); LogRenameSession(RenameLogMessage.UserActionOutcome.Committed, previewChanges); EndRenameSession(); _triggerView.Caret.PositionChanged -= LogPositionChanged; void LogPositionChanged(object sender, CaretPositionChangedEventArgs e) { try { throw new InvalidOperationException("Caret position changed during application of rename"); } catch (InvalidOperationException ex) when(FatalError.ReportAndCatch(ex)) { // Unreachable code due to ReportAndCatch Contract.ThrowIfTrue(true); } } } }
void WaitForAsyncTaskToComplete() { if (!_insideAsync.Value) { _currentAsyncTask?.Join(); } }
public void Test5() { _codeControl.JTF2 = _f.JTF2; _codeControl.SourceText = ""; var w = new Window(); _window = w; w.Content = _codeControl; JoinableTask jt1 = null; w.Loaded += (sender, args) => { jt1 = _codeControl.JTF.RunAsync(() => TestHelper.DoInput1Async(this)); }; try { w.ShowDialog(); } catch (Exception ex) { _f.Debugfn(ex.ToString()); } jt1.Join(); if (_spans != null) { foreach (var timeSpans in _spans) { _outputHelper.WriteLine(string.Join("\t", timeSpans.Select(z => z.TotalMilliseconds))); } } }
public override void StartListening() { _foregroundDispatcher.AssertForegroundThread(); if (_fileChangeUnadviseTask?.IsCompleted == false) { // An unadvise operation is still processing, block the foreground thread until it completes. _fileChangeUnadviseTask.Join(); } if (_fileChangeAdviseTask != null) { // Already listening return; } _fileChangeAdviseTask = _joinableTaskFactory.RunAsync(async() => { try { return(await _fileChangeService.AdviseFileChangeAsync(FilePath, FileChangeFlags, this)); } catch (PathTooLongException) { // Don't report PathTooLongExceptions but don't fault either. } catch (Exception exception) { _errorReporter.ReportError(exception); } return(VSConstants.VSCOOKIE_NIL); }); }
public void DelegationSharesCollection() { var log = new List <FactoryLogEntry>(); var delegatingFactory = new DelegatingFactory(this.asyncPump, this.AddToLog); JoinableTask jt = null; jt = delegatingFactory.RunAsync(async delegate { await Task.Yield(); Assert.True(this.joinableCollection.Contains(jt)); }); jt.Join(); }
/// <summary> /// Blocks, waiting for all background work to finish. /// </summary> /// <param name="cancelUi">Whether UI should be dismissed. If false, this method will return after UI has been rendered</param> /// <param name="dontWaitForUpdatedModel">Returns last available model without block. Used in WYSIWYG mode.</param> /// <param name="token">Token used to cancel the operation, unblock the thread and return null</param> /// <returns></returns> public TModel WaitAndGetResult(bool cancelUi, CancellationToken token) { if (cancelUi) { _uiCancellation.Cancel(); } try { return(_lastJoinableTask.Join(token)); } catch (OperationCanceledException) { return(null); } }
public void WithPriority_LowPriorityCanBlockOnHighPriorityWork() { this.SimulateUIThread(async delegate { var idlePriorityJtf = this.asyncPump.WithPriority(Dispatcher.CurrentDispatcher, DispatcherPriority.ApplicationIdle); var normalPriorityJtf = this.asyncPump.WithPriority(Dispatcher.CurrentDispatcher, DispatcherPriority.Normal); JoinableTask normalTask = null; var unblockNormalPriorityWork = new AsyncManualResetEvent(); var idleTask = idlePriorityJtf.RunAsync(async delegate { await Task.Yield(); unblockNormalPriorityWork.Set(); normalTask.Join(); }); normalTask = normalPriorityJtf.RunAsync(async delegate { await unblockNormalPriorityWork; Assert.False(idleTask.IsCompleted); }); await Task.WhenAll(idleTask.Task, normalTask.Task).WithCancellation(this.TimeoutToken); }); }
public override void StartListening() { _foregroundDispatcher.AssertForegroundThread(); if (_fileChangeUnadviseTask?.IsCompleted == false) { // An unadvise operation is still processing, block the foreground thread until it completes. _fileChangeUnadviseTask.Join(); } if (_fileChangeAdviseTask != null) { // Already listening return; } _fileChangeAdviseTask = _joinableTaskFactory.RunAsync(async() => { try { return(await _fileChangeService.AdviseFileChangeAsync(FilePath, FileChangeFlags, this).ConfigureAwait(true)); } catch (PathTooLongException) { // Don't report PathTooLongExceptions but don't fault either. } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception exception) #pragma warning restore CA1031 // Do not catch general exception types { // Don't explode on actual exceptions, just report gracefully. _errorReporter.ReportError(exception); } return(VSConstants.VSCOOKIE_NIL); }); }
/// <summary> /// Invokes |action| synchronously and returns true on success. |action| is assumed to be /// an rpc using this GrpcConnection's CallInvoker. Note that the CallInvoker might /// restrict the number of threads that can perform rpc concurrently, see e.g. /// PipeCallInvokerFactory. /// Calls on the main thread never run concurrently with asynchronous grpc calls, the /// method blocks until the current async call is completed. /// </summary> public bool InvokeRpc(Action action) { // TODO (internal) Review the calls made from background thread and make them use // InvokeBackgroundRpc // TODO (internal) Make CancelableTask remain on the main thread by default // TODO (internal) Once the above two tasks are resolved, throw in the beginning of // this method if not on the main thread. if (!_taskFactory.Context.IsOnMainThread) { return(DoInvokeSynchronousRpc(action)); } try { _asyncGrpcTask?.Join(); } catch (Exception) { // The exception will be thrown from InvokeRpcAsync and should not be processed in // other places. } return(DoInvokeSynchronousRpc(action)); }
int IDebugStackFrame2.EnumProperties( enum_DEBUGPROP_INFO_FLAGS dwFields, uint nRadix, ref Guid guidFilter, uint dwTimeout, out uint pcelt, out IEnumDebugPropertyInfo2 ppEnum) { pcelt = 0; ppEnum = null; if (guidFilter != Guid.Empty && !Property.Filter.LocalsSelected(ref guidFilter)) { return(VSConstants.S_OK); } InitThread.Join(); pcelt = 0; ppEnum = PropertyEnum.Create(Properties .SelectMany(x => x.Value .Select(y => y.Value.GetInfo(dwFields)))); return(VSConstants.S_OK); }
/// <summary> /// A helper method that just blocks on the completion of a JoinableTask. /// </summary> /// <remarks> /// This method is explicitly defined rather than using an anonymous method because /// we do NOT want the calling method's name embedded into this method's name by the compiler /// so that we can verify based on method name. /// </remarks> private static void OnHangDetected_BlockingMethodHelper(JoinableTask jt) { jt.Join(); }