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

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

    In my case I had a list of jobs that I wanted to run in async from my main method, have been using this in production for quite sometime and works fine.

    static void Main(string[] args)
    {
        Task.Run(async () => { await Task.WhenAll(jobslist.Select(nl => RunMulti(nl))); }).GetAwaiter().GetResult();
    }
    private static async Task RunMulti(List joblist)
    {
        await ...
    }
    

提交回复
热议问题