2.15 — async void: Why It Is Almost Always Wrong¶
← Roadmap · Section: 2. Collections, LINQ and Async Prev: 2.14 CancellationToken · Next: 2.16 Async exceptions
Markers: 🔥 ⚠️ · Confidence: 🔴 · Last reviewed: —
TL;DR¶
- You cannot
awaitanasync voidmethod. The caller has no way to know when it finished, or whether it worked. - An exception inside it cannot be caught by the caller. It goes straight to the top and crashes the process.
- The only acceptable use is a UI event handler, where the signature is forced on you — and even then it needs a try/catch around the whole body.
The concept¶
An async method can return three things: Task, Task<T>, or void.
The first two hand back an object representing the operation — so the caller can wait for it,
check whether it failed, and get a result. async void hands back nothing.
A picture: async Task is posting a letter with tracking. async void is shouting into
a corridor and walking away.
With tracking, you know when it arrived and if it went wrong. Shouting into a corridor gives you nothing — you do not know if anyone heard, when they heard, or whether they fell over trying to act on it.
That missing return value causes two separate serious problems, and the exception one is genuinely dangerous.
How it works¶
Problem 1: you cannot await it¶
public async void SaveData() { await _db.SaveChangesAsync(); }
public void Caller()
{
SaveData(); // returns IMMEDIATELY, work still running
Console.WriteLine("Saved!"); // prints before the save has finished
// There is no way to wait. Nothing was returned to wait ON.
}
The method returns at its first await, exactly as
2.11 describes — but with no Task handed back, the caller
has no handle on it. The work continues invisibly, in the background, unobserved.
This creates race conditions that are maddening to debug, because the code looks sequential.
Problem 2: exceptions crash the process ⚠️¶
This is the serious one.
public async void ProcessAsync()
{
throw new InvalidOperationException("boom");
}
public void Caller()
{
try
{
ProcessAsync(); // the try/catch does NOTHING
}
catch (Exception ex)
{
// NEVER REACHED
Console.WriteLine("caught it");
}
}
Why does the catch not work? Because by the time the exception is thrown, ProcessAsync has
already returned to the caller — the try block finished. The exception happens later, on
whatever thread the continuation runs on.
With async Task, the exception is captured and stored inside the returned Task, so
awaiting it rethrows and your catch works.
With async void there is no Task to store it in. So the runtime raises it on the
synchronization context, or if there is none, on the thread pool as an unhandled
exception — which terminates the process.
// In ASP.NET Core: this brings down your entire application
public async void FireAndForget()
{
await Task.Delay(100);
throw new Exception("boom"); // → process crash. Every in-flight request lost.
}
Not a 500 response. Not a logged error. The whole worker process dies, taking every concurrent request with it. In Kubernetes the container restarts and traffic shifts, and if the bug is triggered by normal traffic it will happen again immediately.
The one legitimate use¶
Event handlers, where the delegate signature is fixed and you cannot return a Task:
private async void Button_Click(object sender, EventArgs e)
{
// 'async void' is forced here — EventHandler returns void
}
And even then, wrap the entire body in a try/catch, because nothing else can:
private async void Button_Click(object sender, EventArgs e)
{
try
{
await DoWorkAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, "Button click failed");
MessageBox.Show("Something went wrong");
}
}
Better still, keep the handler as a thin shell over a testable async Task method:
private async void Button_Click(object sender, EventArgs e)
{
try { await HandleClickAsync(); }
catch (Exception ex) { _logger.LogError(ex, "failed"); }
}
private async Task HandleClickAsync() // testable, awaitable
{
await DoWorkAsync();
}
The trap you will actually hit¶
async void rarely gets written on purpose. It usually appears by accident, through a
lambda passed to a method expecting Action:
// Looks fine. Is async void.
timer.Elapsed += async (s, e) => await DoWorkAsync();
// Also async void — Action returns void
_items.ForEach(async item => await ProcessAsync(item));
// Also async void
Parallel.ForEach(items, async item => await ProcessAsync(item));
The last two are especially nasty. List<T>.ForEach takes an Action<T>, so your async
lambda becomes async void. The loop finishes instantly with every operation still running,
ForEach returns, and the caller carries on thinking the work is done. Any exception crashes
the process.
The fix is an ordinary foreach, or Task.WhenAll:
// Sequential, awaited properly
foreach (var item in items)
await ProcessAsync(item);
// Or concurrent — see 2.12
await Task.WhenAll(items.Select(item => ProcessAsync(item)));
How to spot it: if you write async on a lambda, check what delegate type it is being
assigned to. Action means async void. Func<Task> is fine.
Fire-and-forget done properly¶
Sometimes you genuinely want to start work and not wait — logging telemetry, say. async
void is still the wrong tool:
// WRONG
async void SendTelemetry() { await _client.SendAsync(data); }
// Better — at least the exception is caught rather than crashing
_ = Task.Run(async () =>
{
try { await _client.SendAsync(data); }
catch (Exception ex) { _logger.LogError(ex, "Telemetry failed"); }
});
But in ASP.NET Core, do not do either. Work started this way dies when the request ends
or when the app shuts down, so it silently disappears. Use a proper background mechanism —
IHostedService, a Channel, or a real queue. See
21.1.
Code¶
The full comparison:
// ✗ async void — unawaitable, uncatchable, crashes on failure
public async void SaveAsync(Order o) => await _db.SaveAsync(o);
// ✓ async Task — awaitable, exceptions captured in the task
public async Task SaveAsync(Order o) => await _db.SaveAsync(o);
// ✗ accidental async void via Action<T>
orders.ForEach(async o => await SaveAsync(o));
// ✓ sequential
foreach (var o in orders)
await SaveAsync(o);
// ✓ concurrent
await Task.WhenAll(orders.Select(SaveAsync));
// ✓ the ONLY good async void — an event handler, fully guarded
private async void OnTimerElapsed(object? sender, ElapsedEventArgs e)
{
try
{
await _processor.RunAsync(_cts.Token);
}
catch (OperationCanceledException)
{
// shutting down — normal
}
catch (Exception ex)
{
_logger.LogError(ex, "Timer processing failed");
// MUST swallow here. Rethrowing crashes the process.
}
}
Interview questions¶
Q: Why is async void bad?
Two reasons, and the second is severe. First, it returns nothing, so the caller cannot await
it — there is no way to know when the work finished or whether it succeeded, which produces
race conditions in code that looks sequential. Second, exceptions cannot be caught by the
caller. With async Task the exception is captured inside the returned task and rethrown
when you await it. With async void there is no task to store it in, so it is raised as an
unhandled exception on the thread pool, which terminates the process. In ASP.NET Core that
means the whole application goes down and every in-flight request is lost.
Q: When is async void acceptable?
Only for event handlers, where the delegate signature is fixed as returning void and you have
no choice. Even then the entire body needs a try/catch, because that is the only place the
exception can possibly be handled. My preference is to keep the handler as a thin wrapper —
try/catch around a call to a proper async Task method that holds the real logic, so the
logic stays testable and awaitable.
Q: How does async void usually get into a codebase?
Almost never deliberately. It slips in through lambdas passed to methods that expect an
Action — List<T>.ForEach, Parallel.ForEach, timer event subscriptions. Writing
items.ForEach(async x => await ProcessAsync(x)) looks like it awaits each item, but
ForEach takes an Action<T>, so every lambda is async void. The loop completes instantly
with all the work still running unobserved, and any failure crashes the process. The habit is
to check what delegate type an async lambda is being assigned to — Func<Task> is fine,
Action is not.
Q: How do you do fire-and-forget properly?
In a web application, you usually should not. Work started during a request dies when the
request or the process ends, so it silently disappears — and there is no retry and no
visibility. The right answer is a proper background mechanism: an IHostedService or
BackgroundService reading from a Channel, or a real message queue if the work must
survive a restart. If I truly needed fire-and-forget for something disposable like telemetry,
I would at least use Task.Run with a try/catch inside so a failure is logged rather than
fatal.
Traps ⚠️¶
- A try/catch around an
async voidcall catches nothing. The method already returned. - An unhandled exception in
async voidterminates the process. Not a 500 — a crash. List<T>.ForEachwith an async lambda isasync void. So isParallel.ForEach. UseforeachorTask.WhenAll.- Timer and event subscriptions with async lambdas are
async voidby definition. async voidcannot be tested. There is nothing to await, so a test finishes before the work does.- Fire-and-forget in ASP.NET Core silently dies on request end or shutdown.
- The compiler does not warn you.
async voidis legal C# and looks intentional.
Related¶
- 2.11 async/await internals — why the exception has nowhere to go
- 2.12 Task combinators —
Task.WhenAllinstead of async lambdas in loops - 2.16 Async exceptions — how
Taskcaptures them instead - 1.12 Events — where
async voidis unavoidable - 1.20 Exceptions — general exception handling
- 21.1 Background services — fire-and-forget done right