Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. BatchBlock<int> batchBlock = new BatchBlock<int>(5);
  2.  
  3. async Task Main()
  4. {
  5. async Task Data1Process()
  6. {
  7. Console.WriteLine("S Data1Process");
  8.  
  9.  
  10.  
  11. await Task.Delay(5000);
  12.  
  13. Console.WriteLine("E Data1Process");
  14. }
  15.  
  16. async Task Data2Process()
  17. {
  18. Console.WriteLine("S Data2Process");
  19.  
  20. throw new Exception();
  21.  
  22. await Task.Delay(5000);
  23. Console.WriteLine("E Data2Process");
  24. }
  25.  
  26. var actionBlockExecutor = new ActionBlock<Func<Task>>(async funct =>
  27. {
  28. await funct();
  29. },
  30. new ExecutionDataflowBlockOptions
  31. {
  32. MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded,
  33. EnsureOrdered = true
  34. });
  35.  
  36. actionBlockExecutor.Post(Data1Process);
  37. actionBlockExecutor.Post(Data2Process);
  38. actionBlockExecutor.Complete();
  39.  
  40. Console.WriteLine("Complete");
  41.  
  42. actionBlockExecutor.Completion.Wait();
  43.  
  44. Console.WriteLine("Completed");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement