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

后端 未结 16 2050
后悔当初
后悔当初 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:39

    class Program
    {
         public static EventHandler AsyncHandler;
         static void Main(string[] args)
         {
            AsyncHandler+= async (sender, eventArgs) => { await AsyncMain(); };
            AsyncHandler?.Invoke(null, null);
         }
    
         private async Task AsyncMain()
         {
            //Your Async Code
         }
    }
    

提交回复
热议问题