Why Are My Requests To Web.api Being Blocked By Long Running Controller Code?
Solution 1:
This may be a good situation to implement an asynchronous pattern on your web api backend - you'll be alleviated from your ajax calls blocking once they hit your controller. This can be achieved by leveraging an async
and await
pattern. You'll want to return a Task
, which represents an asynchronous operation.
An example may include...
public async Task<IHttpActionResult> Put(string clientId)
{
var response = await this.yourService.yourSavingMethod(clientId);
return Ok(response);
}
Also see SO question Why is this web api controller not concurrent? for more details and insight on the issue. Furthermore, the default behavior for ASP.NET Session State and can be changed to accommodate concurrent requests. An example may include
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.ReadOnly)
Solution 2:
I think your problem is caused either by browser or ASP.NET. In case it's ASP.NET, take a look at this thread:
In case it's your browser, take a look at this thread with example code:
Why is my async ASP.NET Web API controller blocking the main thread?
Post a Comment for "Why Are My Requests To Web.api Being Blocked By Long Running Controller Code?"