MySQL C# async methods doesn't work?

后端 未结 3 1315
情歌与酒
情歌与酒 2020-12-06 22:04

i have a database in a server and it seems like the async method doesn\'t work.

Here is my code:

static async void Example()
{
    string connectionS         


        
3条回答
  •  一个人的身影
    2020-12-06 22:36

    Well, it could be that there's a pooled connection that's already open. In which case, it would be returned to you synchronously.

    The thing to notice is that await does not necessarily return control back to the calling method. It only returns to the calling method if the status of the task being awaited is TaskStatus.Running. If the task has completed, then execution carries on as normal.

    Try awaiting this method, which returns a task with status RanToCompletion:

    public Task SampleMethod()
    {
        return Task.FromResult(0);
    }
    

提交回复
热议问题