public OleMenuCommandWithBlockingStatus(JoinableTaskFactory joinableTaskFactory, Cancellation _packageCancellation, Func <CancellationToken, Task> callbackAsync, CommandID menuCommandId) { _joinableTaskFactory = joinableTaskFactory; _command = new OleMenuCommand(Execute, menuCommandId); void Execute(object sender, EventArgs eventArgs) { var cancellationTokenSource = _packageCancellation.ResetCommandCancellation(); async Task ExecuteAsync() { await TaskScheduler.Default; await callbackAsync(cancellationTokenSource.Token); } _joinableTaskFactory.RunAsync(ExecuteAsync).Task.Forget(); } }