Tutorial by Examples

// Create a block with an asynchronous action var block = new ActionBlock<string>(async hostName => { IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(hostName); Console.WriteLine(ipAddresses[0]); }); block.Post("google.com"); // Post items to the block's ...
var httpClient = new HttpClient(); // Create a block the accepts a uri and returns its contents as a string var downloaderBlock = new TransformBlock<string, string>( async uri => await httpClient.GetStringAsync(uri)); // Create a block that accepts the content and prints it to t...
public class Producer { private static Random random = new Random((int)DateTime.UtcNow.Ticks); //produce the value that will be posted to buffer block public double Produce ( ) { var value = random.NextDouble(); Console.WriteLine($"Producing value: {value}...
var bufferBlock = new BufferBlock<int>(new DataflowBlockOptions { BoundedCapacity = 1000 }); var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token; var producerTask = Task.Run(async () => { var random = new Random(); while (!cancellati...

Page 1 of 1