async Task vs async void in C#

Shervan360 1,661 Reputation points
2022-08-13T00:41:50.277+00:00

Hello,

I expected the compiler to show an error and tell me "return Task" from the Show method.

Why don't we need to return a Task? Task is a class and I expected to return an instance of Task class.

What is the difference between static async Task Show() and static async void Show() ?
When should we use each one?

(I am beginner to this topic, could you please write a sample example?)

namespace ConsoleApp2  
{  
    internal class Program  
    {  
        static void Main(string[] args)  
        {  
  
        }  
        static async Task Show() // is it equal with 'static async void Show()' ?  
        {  
             // In fact, **Task is a class and I expected to return an instance of Task class.**  
            Console.WriteLine("!");  
            // we don't return anything!  
        }  
    }  
}  
Developer technologies C#
{count} votes

Accepted answer
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-08-13T06:38:05.197+00:00

    You should see siggles as shown below with text explaining what will happen and a recommendation.
    230846-ccc.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.