Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. async void Handle(EventArgs e)
  2. {
  3. await _semaphore.WaitAsync();
  4.  
  5. var thread = new Thread(() =>
  6. {
  7. Process(e);
  8. _semaphore.Release();
  9. _channel.BasicAck(....);
  10. });
  11. thread.Start();
  12. }
  13.  
  14. var workerBlock = new ActionBlock<EventArgs>(
  15. // Process event
  16. e => Process(e),
  17. // Specify a maximum degree of parallelism.
  18. new ExecutionDataflowBlockOptions
  19. {
  20. MaxDegreeOfParallelism = InitialCount
  21. });
  22. var bufferBlock = new BufferBlock();
  23. // link the blocks for automatically propagading the messages
  24. bufferBlock.LinkTo(workerBlock);
  25.  
  26. // asynchronously send the message
  27. await bufferBlock.SendAsync(...);
  28. // synchronously send the message
  29. bufferBlock.Post(...);
  30.  
  31. bufferBlock.LinkTo(cpuWorkerBlock, e => e is CpuEventArgs);
  32. bufferBlock.LinkTo(networkWorkerBlock, e => e is NetworkEventArgs);
  33. bufferBlock.LinkTo(diskWorkerBlock, e => e is DiskEventArgs);
  34.  
  35. bufferBlock.LinkTo(DataflowBlock.NullTarget<EventArgs>);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement