Ejemplo n.º 1
0
		public static Task ContinueWithExceptionHandling(this Task task, Window window, Action<bool> action)
		{
			if (task == null)
				throw new ArgumentNullException(nameof(task));

			if (window == null)
				throw new ArgumentNullException(nameof(window));

			if (action == null)
				throw new ArgumentNullException(nameof(action));

			return task.ContinueWith(t =>
			{
				if (task.IsFaulted)
				{
					Exception ex;

					if (task.Exception != null)
					{
						task.Exception.LogError();
						ex = task.Exception.InnerException;
					}
					else
					{
						ex = new InvalidOperationException(LocalizedStrings.Str2914);
						ex.LogError();
					}

					new MessageBoxBuilder()
							.Caption(LocalizedStrings.Str2915)
							.Text(ex.ToString())
							.Error()
							.Owner(window)
							.Show();
				}

				action(!task.IsFaulted);
			}, TaskScheduler.FromCurrentSynchronizationContext());
		}