Azure Storage Tables: await table.ExecuteAsync(InsertOperation) executes, but never finishes Azure Storage Tables: await table.ExecuteAsync(InsertOperation) executes, but never finishes azure azure

Azure Storage Tables: await table.ExecuteAsync(InsertOperation) executes, but never finishes


The problem is here:

Task.WaitAll(addPostTasks.ToArray());

Your async method tries to marshal itself back to the ASP.NET synchronization context, which is stuck because you initiated a blocking call using Task.WaitAll.

Instead, you'll need to follow the async all the way pattern and use Task.WhenAll, and await on that:

await Task.WhenAll(addPostTasks.ToArray);

Stephan Cleary elaborates on this in his blog post (which @NedStoyanov added):

One other important point: an ASP.NET request context is not tied to a specific thread (like the UI context is), but it does only allow one thread in at a time. This interesting aspect is not officially documented anywhere AFAIK, but it is mentioned in my MSDN article about SynchronizationContext.


This is a classic deadlock caused by this line:

Task.WaitAll(addPostTasks.ToArray());

try changing it to:

await Task.WhenAll(addPostTasks.ToArray());

Basically the the Task.WaitAll blocks the request thread and it is unable to execute the continuation of the Tasks initiated by await table.ExecuteAsync(...). Another alternative is to use ConfigureAwait(false) on your internal tasks to avoid switching SynchronizatonContext.

await table.ExecuteAsync(...).ConfigureAwait(false);

You can use ConfigureAwait(false) whenever you do not require to switch to the original SynchronizationContext. In your case I believe you can do that with all awaits as you are on the server and it shouldn't matter if the code after await executes on the thread pool or not.

See this article for more details: msdn.microsoft.com/enus/magazine/jj991977.aspx


If you are working for an organisation,The problem may be with the proxy settings enabled by your organisation. I had a similar issue and to solve that i used the following steps:

1:Add the following codde in Configure at startup.cs

app.UseDeveloperExceptionPage();                var webProxy = new WebProxy(new Uri(Configuration["defaultProxy:proxyaddress"]), BypassOnLocal: false);                var proxyHttpClientHandler = new HttpClientHandler                {                    Proxy = webProxy,                    UseProxy = true,                };                AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

2: Add the at appsettings.json

"defaultProxy": {    "proxyaddress": "<your IP here>"  },