private static async Task queueData(ActionBlock <MyObj> executor) { for (int i = 0; i < 20; ++i) { Console.WriteLine("Queuing data " + i); MyObj data = new MyObj(i.ToString()); await executor.SendAsync(data); } Console.WriteLine("Indicating that no more data will be queued."); executor.Complete(); // Indicate that no more items will be queued. Console.WriteLine("Waiting for queue to empty."); await executor.Completion; // Wait for executor queue to empty. }
private static void process(MyObj data) { Console.WriteLine("Processing data " + data.Data); Thread.Sleep(200); // Simulate load. }