C
C
CallMeYourDaddy2020-08-27 09:42:44
C++ / C#
CallMeYourDaddy, 2020-08-27 09:42:44

How to call an async method in Main?

How to correctly call an asynchronous method in the main (Main)?
I do like this:

private static void Main(string[] args)
            => new Bot().RunAsync().GetAwaiter().GetResult();

I also heard about GenericHost , but did not figure out how to call the desired method. How are you doing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolay, 2020-08-27
@CallMeYourDaddy

Do

private static async Task Main(string[] args)
    => await new Bot.RunAsync();

V
Vladimir Korotenko, 2020-08-28
@firedragon

Can be used .
.Wait()
Task.Run

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question