© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•5mo ago•
19 replies
RiA

async void

I have a 'void' return type method that needs to launch an async method.

1. I could use try-catch (I'm used to this approach usually, since the errors can be wrapped up)
private async void SomeLegacyHandler()
{
  try { await TargetMethodAsync(); }
  catch(ex) { /*handle logging*/ }
}
private async void SomeLegacyHandler()
{
  try { await TargetMethodAsync(); }
  catch(ex) { /*handle logging*/ }
}

2. Another suggested answer: Always successful Task (handle exception on the async Task pipeline directly)
Couldn't the Task method here just be made async anyway? (I mean i know it works without the async, but feels pointless unless deferred awaiting here improves performance in a way i can't see yet)
private Task SomeLegacyHandlerAsync()
{
  try { return TargetMethodAsync(); }
  catch(ex) { /*handle logging*/ return Task.CompletedTask; }
}
private async void SomeLegacyHandler()
  => await SomeLegacyHandlerAsync();
private Task SomeLegacyHandlerAsync()
{
  try { return TargetMethodAsync(); }
  catch(ex) { /*handle logging*/ return Task.CompletedTask; }
}
private async void SomeLegacyHandler()
  => await SomeLegacyHandlerAsync();

3.
ContinueWith
ContinueWith
(this is my main confusion; Does this work? Is this better than #1?)
private void SomeLegacyHandler()
{
  _ = await SomeLegacyHandlerAsync()
  .ContinueWith(task => {
    if (task.Exception != null)
      // log here
  }, TaskContinuationOptions.OnlyOnFaulted);
}
private void SomeLegacyHandler()
{
  _ = await SomeLegacyHandlerAsync()
  .ContinueWith(task => {
    if (task.Exception != null)
      // log here
  }, TaskContinuationOptions.OnlyOnFaulted);
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Async void method testing in xUnit
C#CC# / help
12mo ago
❔ async void in event handler (window "OnClosing" event)
C#CC# / help
3y ago
❔ This is not a .NET bug, right? (async void)
C#CC# / help
4y ago
✅ static, public, void
C#CC# / help
16mo ago