| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
#if !NO_SYNCCTX |
| 4 |
using System; |
| 5 |
using System.Collections.Generic; |
| 6 |
using System.Linq; |
| 7 |
using System.Text; |
| 8 |
using System.Threading; |
| 9 |
|
| 10 |
namespace System.Reactive.Concurrency |
| 11 |
{ |
| 12 |
internal static class SynchronizationContextExtensions |
| 13 |
{ |
| 14 |
public static void PostWithStartComplete<T>(this SynchronizationContext context, Action<T> action, T state) |
| 15 |
{ |
| 16 |
context.OperationStarted(); |
| 17 |
|
| 18 |
context.Post( |
| 19 |
o => |
| 20 |
{ |
| 21 |
try |
| 22 |
{ |
| 23 |
action((T)o); |
| 24 |
} |
| 25 |
finally |
| 26 |
{ |
| 27 |
context.OperationCompleted(); |
| 28 |
} |
| 29 |
}, |
| 30 |
state |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
public static void PostWithStartComplete(this SynchronizationContext context, Action action) |
| 35 |
{ |
| 36 |
context.OperationStarted(); |
| 37 |
|
| 38 |
context.Post( |
| 39 |
_ => |
| 40 |
{ |
| 41 |
try |
| 42 |
{ |
| 43 |
action(); |
| 44 |
} |
| 45 |
finally |
| 46 |
{ |
| 47 |
context.OperationCompleted(); |
| 48 |
} |
| 49 |
}, |
| 50 |
null |
| 51 |
); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
#endif |