Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:57:48+00:00 2026-06-04T08:57:48+00:00

This does not throw compile error, but why? public async void DoSomething(object arg){ …

  • 0

This does not throw compile error, but why?

public async void DoSomething(object arg){ ... }

Action<object> myAnonActionDelegate = DoSomething;

Shouldn’t “DoSomething” have a signature of type Func<object,Task> as opposed to Action? In fact “DoSomething” is not be assignable to Func<object,Task> delegate.

The question is why? Is my understanding about async keyword off?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:57:50+00:00Added an answer on June 4, 2026 at 8:57 am

    Shouldn’t “DoSomething” have a signature of type Func<object,Task> as opposed to Action?

    No – the method doesn’t return anything. Look at the declaration – it’s void, not Task. The async part is just for the compiler’s benefit (and humans reading it) – it’s not really part of the signature of the method. An async method must return either void, Task, or Task<T> – but the return type of the method really is just what you declare it to be. The compiler doesn’t turn your void into Task magically.

    Now you could write the exact same method body and declare the method as:

    public async Task DoSomething(object arg){ ... }
    

    at which point you would need to use Func<object, Task> – but that’s a different method declaration.

    I would strongly advise you to use the form returning Task unless you’re using an async method to subscribe to an event – you might as well allow callers to observe your method’s progress, failure etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code does not throw an error but the query fails, that is, the
Why does this not throw an error: echo texto em cirílico sem conversão; echo
Why does this generate a compiler error: class X { public void Add(string str)
This does not really apply to any language specifically, but if it matters I
I just found my code like this does not compile right? Is there any
This does NOT work: Sub X() Dim A As Access.Application Set A = CreateObject(Access.Application)
Ops: This does not belong to ServerFault because it focuses on Programing Architecture. I
can anyone tell me why this does not work Excel.Worksheet ws_res = (Excel.Worksheet) wb.Worksheets.Add(mis,
How can I ensure that this does NOT open in a new window?? onclick=ob=this.form.table;window.open(ob.options[ob.selectedIndex].value)/>
This works: Entities.WorkOrderSet.Where(MyCustomMethod); This does not: Entities.WorkOrderSet.Where(o => MyCustomMethod(o)); ( [Edit] Even without new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.