public static TTask WithBusyIndicator <TTask>([NotNull] this TTask task, [NotNull] IViewModel viewModel, object message = null, bool?handleException = null) where TTask : Task { Should.NotBeNull(task, nameof(task)); Should.NotBeNull(viewModel, nameof(viewModel)); if (handleException == null) { handleException = ApplicationSettings.HandleTaskExceptionBusyIndicator; } if (task.IsCompleted) { if (handleException.Value) { ToolkitExtensions.TryHandleTaskException(task, viewModel, viewModel.GetIocContainer(true)); } return(task); } var token = viewModel.BeginBusy(message); task.TryExecuteSynchronously(t => { token.Dispose(); if (handleException.Value) { ToolkitExtensions.TryHandleTaskException(t, viewModel, viewModel.GetIocContainer(true)); } }); return(task); }