1
0

SynchronizationContextExtensions.cs 1.4 KB

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