Line | |
---|
1 | /*using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using System.Diagnostics;
|
---|
7 | using System.Windows.Threading;
|
---|
8 |
|
---|
9 | namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary
|
---|
10 | {
|
---|
11 | public static class TaskExtensions
|
---|
12 | {
|
---|
13 | /// <summary>
|
---|
14 | /// Logs exceptions that occur during task execution.
|
---|
15 | /// </summary>
|
---|
16 | /// <param name="task">The task.</param>
|
---|
17 | /// <returns></returns>
|
---|
18 | public static Task WithExceptionLogging(this Task task)
|
---|
19 | {
|
---|
20 | return task.ContinueWith(t =>
|
---|
21 | {
|
---|
22 | var exception = t.Exception;
|
---|
23 | if (exception != null)
|
---|
24 | {
|
---|
25 | if (exception.InnerException != null)
|
---|
26 | exception = exception.InnerException;
|
---|
27 |
|
---|
28 | Debug.WriteLine("Failure in async task: " + exception.Message);
|
---|
29 | }
|
---|
30 | }, TaskContinuationKind.OnFailed);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /// <summary>
|
---|
34 | /// Rethrows exceptions thrown during task execution in thespecified dispatcher thread.
|
---|
35 | /// </summary>
|
---|
36 | /// <param name="task">The task.</param>
|
---|
37 | /// <param name="dispatcher">The dispatcher.</param>
|
---|
38 | /// <returns></returns>
|
---|
39 | public static Task WithExceptionThrowingInDispatcher(this Task task, Dispatcher dispatcher)
|
---|
40 | {
|
---|
41 | return task.ContinueWith(t =>
|
---|
42 | {
|
---|
43 | dispatcher.BeginInvoke(() =>
|
---|
44 | {
|
---|
45 | throw t.Exception;
|
---|
46 | }, DispatcherPriority.Send);
|
---|
47 | }, TaskContinuationKind.OnFailed);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | */ |
---|
Note: See
TracBrowser
for help on using the repository browser.