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

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

    When the C# 5 CTP was introduced, you certainly could mark Main with async... although it was generally not a good idea to do so. I believe this was changed by the release of VS 2013 to become an error.

    Unless you've started any other foreground threads, your program will exit when Main completes, even if it's started some background work.

    What are you really trying to do? Note that your GetList() method really doesn't need to be async at the moment - it's adding an extra layer for no real reason. It's logically equivalent to (but more complicated than):

    public Task> GetList()
    {
        return new GetPrograms().DownloadTvChannels();
    }
    

提交回复
热议问题