private void WatchLoop() { foreach (var r in RequestChannel.GetConsumingEnumerable()) { var request = r; // capture variable Thread.Sleep(request.Value * 1000); // BAD PRACTICE (should be await Task.Delay) var item = new CorrelationItem <string>(request.Correlation, $"Data of {request.Value}"); ResponseChannel.TryAdd(item); } }
private void WatchLoopAsync() { foreach (var r in RequestChannel.GetConsumingEnumerable()) { var request = r; // capture variable var t = Task.Run(async() => { await Task.Delay(request.Value * 1000).ConfigureAwait(false); var item = new CorrelationItem <string>(request.Correlation, $"Data of {request.Value}"); ResponseChannel.TryAdd(item); }); t.Start(); } }
private void WatchLoop() { foreach (var r in RequestChannel.GetConsumingEnumerable()) { var request = r; // capture variable var t = new Thread(() => { Thread.Sleep(request.Value * 1000); // BAD PRACTICE var item = new CorrelationItem <string>(request.Correlation, $"Data of {request.Value}"); ResponseChannel.TryAdd(item); }); t.Start(); } }