Azure downloadtostreamasync method freezes

here is the violation code

    public async static Task<MemoryStream> AsyncReadBlob(string identifier)
    {
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageString);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(containerName);
        MemoryStream memstream = new MemoryStream();
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(identifier);
        await blockBlob.DownloadToStreamAsync(memstream);
        return memstream;
    }

Basically, the code works completely fine if I replaced

await blockBlob.DownloadToStreamAsync(memstream)

with

blockblob.DownloadToStream(memstream)

or

blockblob.DownloadToStreamAsync(memstream).wait()

But the moment I make it asynchronous, the download to stream step never completes. I also tried using DownloadToStreamBegin () and then waited for it to finish, but it never ends, again.

Does it work because it is a static method? Or is it because its memstream is erased from memory or something like that.

I am using asp.net 4.5, everything compiles correctly, there are no interpreter errors or exceptions.

Any help would be greatly appreciated.

+4
2

... :

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

:

#, , , .

, ( ) ASP.NET , . , , , . , .

ConfigureAwait .

+9

Task<T>.Result Task.Wait AsyncReadBlob, . .

- Result Wait await.

+3

All Articles