Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

c# async void: Exception Risks and Safe Patterns

Learn how c# async void behaves, why it can crash your app, and when it's acceptable to use in event handlers.

~4 min readC#
#async-void#C##exception-handling#event-handlers
Illustration of an async void method with an unhandled exception causing an application crash, showing a broken chain link.

In C#, an async void method is an asynchronous method that returns void instead of Task. The signature exists primarily to support event handlers, but its exception behavior makes it dangerous outside that context. This article explains how async void works, why it can crash your application, and when it is the right choice.

What async void Does Differently

An async void method is declared like this:

csharp
public async void LoadData() { var data = await FetchDataAsync(); // process data }

Syntactically, the only difference from async Task is the return type. The runtime behavior differs in two important ways. First, an async void method cannot be awaited by the caller. The caller receives no Task to track completion or observe exceptions. Second, exceptions thrown inside an async void method are not captured by the caller. The runtime posts the exception to the current SynchronizationContext; if there is no context, the exception is sent to the thread pool. If nothing handles it, the process terminates.

Unhandled Exceptions Can Crash the Process

Consider this code:

csharp
public async void Process() { await Task.Delay(100); throw new InvalidOperationException("Failed"); }

Process starts executing synchronously until the first await. The exception is thrown after the await resumes, so it is delivered through the synchronization context rather than returned to the caller. Depending on the context, it can surface on a UI thread or a thread-pool thread. Because the method returns void, no Task can carry the exception.

In a console application, an unhandled exception from an async void method crashes the process. In a desktop UI application, a global exception event may let you observe the failure, but it is not a guaranteed recovery path and the application can still terminate. In any process, an unhandled exception can terminate the application. This is the core reason async void is discouraged for anything except event handlers.

Why async void Cannot Be Awaited

Because async void returns void, the caller has no Task to await. The following code does not compile:

csharp
// This does not compile: cannot await void await Process();

You cannot catch exceptions from the caller's perspective. Installing a global handler such as AppDomain.UnhandledException only observes the failure after it is too late to recover. UI frameworks may expose exception events, but those events are not a substitute for a catch block inside the method. The lack of a returned Task also makes it difficult to sequence operations after the method completes.

When async void Is Acceptable: Event Handlers

Standard event handlers such as EventHandler return void, so they cannot directly use an async Task method as their delegate target. For example, a button click handler in a desktop app uses async void:

csharp
private async void OnButtonClick(object sender, EventArgs e) { var result = await LoadDataAsync(); UpdateUI(result); }

Here, async void matches the delegate signature. If the handler is called on a UI thread, the await captures the current SynchronizationContext, so the continuation resumes on the UI thread. This makes it natural for updating UI state.

async void is appropriate for event handlers because it is the direct way to write an asynchronous handler for a void delegate. It is not automatically safe. If LoadDataAsync or UpdateUI throws and the exception escapes, it can still crash the application. Treat the handler as a top-level entry point: it should handle its own exceptions.

Handling Exceptions in async void Event Handlers

Wrap the body of an async void event handler in a try-catch block to prevent exceptions from escaping:

csharp
private async void OnButtonClick(object sender, EventArgs e) { try { var result = await LoadDataAsync(); UpdateUI(result); } catch (Exception ex) { // Log the exception and show a user-friendly message MessageBox.Show($"Error: {ex.Message}"); } }

This handles the exception on the UI thread and lets the application continue. Keep the try-catch inside the method; callers of an async void method cannot catch the exception for you.

Prefer async Task for Non-Event Code

For any method that is not an event handler, use async Task or async Task<T> instead. This gives the caller the ability to await, catch exceptions, and control flow:

csharp
public async Task LoadDataAsync() { var data = await FetchDataAsync(); // process data } // Caller can await and handle errors public async Task CallerAsync() { try { await LoadDataAsync(); } catch (Exception ex) { // Handle exception } }

This pattern is safer and more flexible. If you need to call an async Task method from a synchronous method, you can use .GetAwaiter().GetResult(), but that can cause deadlocks in UI contexts when the captured SynchronizationContext is blocked. Prefer await all the way up.

Practical Guidance for Fire-and-Forget Scenarios

Sometimes you need to start an asynchronous operation without waiting for it. This is often called fire-and-forget. Avoid using async void for this purpose. Instead, use async Task and explicitly handle exceptions:

csharp
public async Task FireAndForgetAsync() { try { await DoWorkAsync(); } catch (Exception ex) { // Log the exception, but do not rethrow LogError(ex); } } // Caller ignores the task, but exceptions are handled internally _ = FireAndForgetAsync();

Because the method handles its own exceptions, the caller can discard the task without causing an unhandled exception. If you later need to know when the operation finishes or whether it failed, store the task and await it.

If you must use async void outside an event handler, you are responsible for every exception. The safest approach is to wrap the entire method body in a try-catch and never let an exception escape. But even then, you lose the ability to know when the method finishes, which can lead to race conditions and resource leaks.

In summary, async void is a narrow tool designed for standard event handlers. For all other asynchronous code, prefer async Task. When you do use async void, handle exceptions locally and never assume the caller can observe them. The exception behavior is the key difference, and it is why async void is a common source of production crashes.

Try matching browser tools

All tools

Small utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.

All C# guides

More in C#

All C# guides

The guides filed next to this one in C#, in library order.