public WaitIndicatorResult <T> Run <T>(string title, string message, bool allowCancel, Func <IWaitContext, Task <T> > asyncMethod, int totalSteps = 0) { _joinableTaskContext.VerifyIsOnMainThread(); using IWaitContext waitContext = new VisualStudioWaitContext(_waitDialogFactoryService.Value, title, message, allowCancel, totalSteps); try { #pragma warning disable VSTHRD102 // Deliberate usage T result = _joinableTaskContext.Factory.Run(() => asyncMethod(waitContext)); #pragma warning restore VSTHRD102 return(WaitIndicatorResult <T> .FromResult(result)); } catch (OperationCanceledException) { return(WaitIndicatorResult <T> .Cancelled); } catch (AggregateException aggregate) when(aggregate.InnerExceptions.All(e => e is OperationCanceledException)) { return(WaitIndicatorResult <T> .Cancelled); } }
public Callback(VisualStudioWaitContext waitContext) { _waitContext = waitContext; }