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

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

    You can do this without needing external libraries also by doing the following:

    class Program
    {
        static void Main(string[] args)
        {
            Bootstrapper bs = new Bootstrapper();
            var getListTask = bs.GetList(); // returns the Task>
    
            Task.WaitAll(getListTask); // block while the task completes
    
            var list = getListTask.Result;
        }
    }
    

提交回复
热议问题