Should I avoid 'async void' event handlers?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
async void is usually discouraged in C sharp because it breaks normal task based composition and exception handling. Event handlers are the one common exception, since framework delegate signatures typically require void. The right rule is not absolute avoidance, but strict containment: use async void only at event boundaries and keep real work in Task methods.
Why async void Is Different
Methods returning Task can be awaited, chained, cancelled, and tested with standard async tools. async void methods cannot be awaited by callers, which means completion and failure cannot be observed in the same way.
Consequences include:
- harder error propagation
- reduced testability
- unclear lifecycle for calling code
Example of risky non event use:
A caller cannot await this or catch exceptions through normal await flow.
Event Handlers Are a Valid Exception
UI frameworks define event delegates that return void, so event handlers often must be async void.
The handler is acceptable because signature is fixed by framework contract.
Keep Handlers Thin, Move Logic to Task
To limit risk, keep only orchestration in the handler and move business logic to task returning methods.
Now core logic is reusable and testable.
Exception Handling Guidance
Always add local try and catch in async void event handlers. Unhandled exceptions in these handlers can crash UI contexts or surface through global exception handlers with limited context.
Pattern:
- catch known transient exceptions and show user message
- log unexpected exceptions with action metadata
- keep global handler as safety net, not primary handling
Reentrancy and Double Click Protection
Event handlers can be triggered repeatedly before prior async work finishes. Guard against overlap.
You can also disable the triggering control during execution for better UX.
Testing Strategy
Do not try to test async void directly when avoidable. Test the extracted Task methods.
This keeps tests deterministic and aligned with task based async behavior.
Library and Service Code Rule
For libraries, repositories, services, and controllers, return Task or Task of value. async void in these layers is almost always a design bug.
If you need fire and forget behavior, create a supervised background mechanism with explicit logging and exception capture rather than raw async void.
Common Pitfalls
A common pitfall is writing large business workflows directly inside an event handler. This hides logic behind UI signatures and makes failures harder to test.
Another issue is missing exception handling in event handlers, which leads to fragile behavior under real network failures.
Teams also forget reentrancy controls, causing duplicate submissions when users click quickly.
Summary
- Avoid
async voidfor normal methods and returnTaskinstead. - Use
async voidonly for framework event handler signatures. - Keep handlers thin and delegate real work to task returning methods.
- Catch and log exceptions locally inside event handlers.
- Add reentrancy guards to prevent overlapping user actions.
Related reading
- Should I be using process.nextTick
- Should I offload work to other threads in ASP.NET?
- Should I use async all the way for my GUI app?
- Should i use ThreadPools or Task Parallel Library for IO-bound operations
- Should I bind to ICollectionView or ObservableCollection
- Should I derive custom exceptions from Exception or ApplicationException in .NET?
- Should I worry about This async method lacks 'await' operators and will run synchronously warning
- Should I worry about This async method lacks 'await' operators and will run synchronously warning

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.