Can't specify the 'async' modifier on the 'Main' method of a console app

后端 未结 16 2035
后悔当初
后悔当初 2020-11-21 07:44

I am new to asynchronous programming with the async modifier. I am trying to figure out how to make sure that my Main method of a console applicati

16条回答
  •  忘了有多久
    2020-11-21 08:43

    Haven't needed this much yet, but when I've used console application for Quick tests and required async I've just solved it like this:

    class Program
    {
        static void Main(string[] args)
        {
            MainAsync(args).Wait();
        }
    
        static async Task MainAsync(string[] args)
        {
            // Code here
        }
    }
    

提交回复
热议问题