Why can't I debug code in an async method?

后端 未结 2 758
刺人心
刺人心 2020-12-14 01:08

I actually started the night trying to learn more about MongoDB, but am getting hung up and the .NET await/async stuff. I am trying to implement the code shown on MongoDB\'s

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 01:29

    I' not so good with async dev and had a similar problem, however I was kicking off the async method in Main like:

    Task.Run(async () => await GetDataAsync());
    

    I think the Garbage Collector was disposing of the anonymous method as nothing had a reference to it anymore. Using Fabien's .Wait() allowed me to step through the program and debug. I am using netcore 2.1 with vs2017

提交回复
热议问题