NetMQSynchronizationContext.cs 908 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. #if !NET35
  4. namespace NetMQ
  5. {
  6. internal sealed class NetMQSynchronizationContext : SynchronizationContext
  7. {
  8. private readonly NetMQPoller m_poller;
  9. public NetMQSynchronizationContext(NetMQPoller poller)
  10. {
  11. m_poller = poller;
  12. }
  13. /// <summary>Dispatches an asynchronous message to a synchronization context.</summary>
  14. public override void Post(SendOrPostCallback d, object state)
  15. {
  16. var task = new Task(() => d(state));
  17. task.Start(m_poller);
  18. }
  19. /// <summary>Dispatches a synchronous message to a synchronization context.</summary>
  20. public override void Send(SendOrPostCallback d, object state)
  21. {
  22. var task = new Task(() => d(state));
  23. task.Start(m_poller);
  24. task.Wait();
  25. }
  26. }
  27. }
  28. #endif