Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

C# async void vs Task: Key Differences

C# async void vs Task: learn how their exception behavior and awaitability differ, when async void is required, and why async Task is the safer default.

~4 min readC#
#async#C##Task#exception handling
Diagram contrasting async void and async Task in C#, showing exception flow and awaitability

In C#, an async method's return type determines how errors propagate and whether callers can await the operation. The choice between async void and async Task is not stylistic; it changes runtime behavior, especially exception propagation and the ability to observe completion.

The Core Difference: Return Type and Awaitability

An async Task method returns a Task (or a Task<T> when it returns a value) that represents the ongoing operation. Callers can await that task, inspect its status, and observe exceptions when the task completes. An async void method returns nothing; it is fire-and-forget from the caller's perspective. The caller cannot await it, cannot observe exceptions that surface after an await, and has no way to know when it finishes.

csharp
public async Task<int> FetchValueAsync() { await Task.Delay(100); return 42; } public async void FireAndForget() { await Task.Delay(100); // No return value, caller cannot await }

Because async void returns no Task, the compiler does not produce an awaitable handle for the caller. The method starts executing synchronously until the first await, then returns control to the caller. Any subsequent work continues on the captured synchronization context if one exists; otherwise it runs on the thread pool. Either way, the caller has no handle to the operation.

How Exceptions Behave Differently

Exceptions thrown inside an async Task method are captured by the returned Task. When you await that task, the exception is rethrown at the await point, allowing normal try/catch handling. If you never await the task, the exception is still captured, but it may be observed later via Task.WhenAll or Task.Wait.

With async void, exceptions that occur after an await are not captured in a Task. They are delivered to the current SynchronizationContext, or to the thread pool if there is no synchronization context. In a UI application, the exception surfaces through the synchronization context and typically reaches a framework-level unhandled-exception handler, such as WPF's Application.DispatcherUnhandledException. In ASP.NET Core and other host environments without a synchronization context, an exception that occurs after an await is posted to the thread pool and can crash the process if unhandled.

csharp
public async Task<int> DivideAsync(int a, int b) { await Task.Yield(); return a / b; // DivideByZeroException captured in Task } public async void RaiseException() { await Task.Yield(); throw new InvalidOperationException("No task to capture this"); }

If you call RaiseException() without an appropriate exception handler, the exception will surface through the ambient synchronization context or thread pool and can terminate the application. This is the primary reason async void is dangerous outside event handlers.

Why async Task Is Required for Awaitability

Any method declared as async void cannot be awaited. The caller cannot sequence operations after it completes, cannot observe exceptions, and cannot receive a Task that represents the operation. The method can still accept a CancellationToken for cooperative cancellation, but the caller has no awaitable handle to use to observe when cancellation or completion happens. In contrast, async Task gives the caller full control: you can await, Task.WhenAny, Task.WhenAll, or pass it to other methods that accept Task.

csharp
public async Task ProcessAsync() { await Task.Delay(100); } public async void ProcessVoid() { await Task.Delay(100); } public async Task CallerAsync() { await ProcessAsync(); // Works // await ProcessVoid(); // Compiler error: cannot await void }

The inability to await async void also prevents normal exception handling for the asynchronous part of the method. You can wrap the call in a try/catch, but it will not catch exceptions thrown after the method hits an await, because the call has already returned and there is no task to observe. This forces developers to rely on global handlers, which is fragile.

The Only Acceptable Use Case: Event Handlers

Event handlers in C# have a signature that returns void. The .NET event pattern requires void for most events, such as button clicks or timer ticks. When you need to call await inside an event handler, you must declare it as async void because the delegate type does not allow Task.

csharp
button.Click += async (sender, e) => { await LoadDataAsync(); UpdateUI(); };

This is the one scenario where async void is the only option. The event system does not await the handler, so the method is inherently fire-and-forget. The risk of unhandled exceptions remains, so you must add a try/catch inside the handler to prevent application crashes.

Handling Errors in async void Safely

If you must use async void for an event handler, wrap the entire body in a try/catch and handle the exception explicitly. This prevents the exception from escaping to the synchronization context and crashing the app.

csharp
private async void OnButtonClick(object sender, EventArgs e) { try { await LoadDataAsync(); UpdateUI(); } catch (Exception ex) { // Log the exception and show a user-friendly message Logger.LogError(ex, "Failed to load data"); statusLabel.Text = "Load failed"; } }

This pattern is acceptable because the event handler is the boundary where the exception can be handled locally. For any other method, prefer async Task and let the caller decide how to handle errors.

Testing and Maintainability Concerns

async void methods are difficult to unit test because the test runner cannot await them. A test that calls an async void method may finish before the asynchronous work completes, leading to flaky tests or false positives. With async Task, you can simply await the method in your test and assert on the result or exception.

csharp
[Fact] public async Task FetchValue_ReturnsExpected() { var result = await _service.FetchValueAsync(); Assert.Equal(42, result); }

If FetchValueAsync were async void, you would need to add delays or use Task.Delay to wait for completion, which is unreliable. The maintainability benefit of async Task extends beyond tests: it makes the method composable, works naturally with CancellationToken, and gives callers a clear contract for completion and failure.

Decision Guidance: When to Use Each

Use async Task for any method that performs asynchronous work and is not an event handler. This includes public APIs, service methods, and helper functions. Use async void only when the method is an event handler and the delegate signature forces void.

Criterionasync Taskasync void
Caller can awaitYesNo
Exception propagationCaptured in Task, awaitablePosted to sync context, unhandled
Unit testingStraightforward with awaitRequires workarounds
Cancellation supportYes, via CancellationTokenNot directly
Typical useAll non-event methodsEvent handlers only

If you are writing a method that returns a value, always use async Task<T>. If the method returns no value, use async Task. Reserve async void for the rare event handler case, and even then, handle exceptions inside the method to avoid crashing the application.

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.