Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async void Handle(EventArgs e)
- {
- await _semaphore.WaitAsync();
- var thread = new Thread(() =>
- {
- Process(e);
- _semaphore.Release();
- _channel.BasicAck(....);
- });
- thread.Start();
- }
- var workerBlock = new ActionBlock<EventArgs>(
- // Process event
- e => Process(e),
- // Specify a maximum degree of parallelism.
- new ExecutionDataflowBlockOptions
- {
- MaxDegreeOfParallelism = InitialCount
- });
- var bufferBlock = new BufferBlock();
- // link the blocks for automatically propagading the messages
- bufferBlock.LinkTo(workerBlock);
- // asynchronously send the message
- await bufferBlock.SendAsync(...);
- // synchronously send the message
- bufferBlock.Post(...);
- bufferBlock.LinkTo(cpuWorkerBlock, e => e is CpuEventArgs);
- bufferBlock.LinkTo(networkWorkerBlock, e => e is NetworkEventArgs);
- bufferBlock.LinkTo(diskWorkerBlock, e => e is DiskEventArgs);
- bufferBlock.LinkTo(DataflowBlock.NullTarget<EventArgs>);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement