.Result / .Wait() = sync-over-async: it blocks a thread pool thread and under load causes thread pool starvation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // ====================================================================== // Q: What's wrong here? // // - .Result / .Wait() = sync-over-async: it blocks a thread pool thread and // under load causes thread pool starvation. In legacy ASP.NET or a UI context // it can also deadlock. // - async void: exceptions cannot be caught and can crash the whole process. Use // it only for event handlers; this should be async Task. // - The CancellationToken is missing. // ====================================================================== public IActionResult Sync() { var result = _erpClient.GetPricesAsync().Result; return Ok(result); } public async void OnOrderCreated(Order o) => await _bus.PublishAsync(o); |