Azure downloadtostreamasync method hangs

前端 未结 2 993
鱼传尺愫
鱼传尺愫 2021-01-11 10:55

here is the offending code

    public async static Task AsyncReadBlob(string identifier)
    {
        CloudStorageAccount storageAccount         


        
2条回答
  •  伪装坚强ぢ
    2021-01-11 11:39

    Short version... Use:

     await blockBlob.DownloadToStreamAsync(memstream).ConfigureAwait(false);
    

    Long version:

    When you await a task in C#, the task scheduler will try to execute the block of code that comes after the await in the same thread that called the original await.

    The problem is that in some cases (can't recall right now the specific circumstances) the ASP.NET Thread Scheduler will block the thread while waiting for the Task to return. When the task returns, the task blocks waiting for the original thread to be released, while the thread is blocked waiting for the task to end. So you end deadlocked.

    ConfigureAwait allows you to deactivate that behavior.

提交回复
热议问题