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

后端 未结 16 2074
后悔当初
后悔当初 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条回答
  •  猫巷女王i
    2020-11-21 08:27

    To avoid freezing when you call a function somewhere down the call stack that tries to re-join the current thread (which is stuck in a Wait), you need to do the following:

    class Program
    {
        static void Main(string[] args)
        {
            Bootstrapper bs = new Bootstrapper();
            List list = Task.Run((Func>>)bs.GetList).Result;
        }
    }
    

    (the cast is only required to resolve ambiguity)

提交回复
热议问题