Reputation: 4249
I want a client connection to wait for some data that may come 3 or 4 seconds later.
The idea was to make a Thread.sleep and recheck some times but I don't want to stuck other clients because some clients won't have to wait but some do.
I'm new to MVC and hope that you can give me some suggestions.
/edit If I use this code:
public string weatherAsync(string city)
{
AsyncManager.OutstandingOperations.Increment();
Task.Factory.StartNew(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(10));
AsyncManager.Parameters["output"] = DateTime.Now.TimeOfDay.ToString();
AsyncManager.OutstandingOperations.Decrement();
});
return null;
}
public string weatherCompleted(string output)
{
return output;
}
And request my page two times at the same time the first one returns the time after about 10 seconds and AFTER that the second page need 10 more seconds to return the output :-/
Is this a problem of my controller or Thread.sleep?
Upvotes: 0
Views: 9312
Reputation: 5103
Thread.Sleep will not block other users but it will block current thread so it cannot be reused by other clients.
If you are doing call to some external web service in your controller please take a look on asyncronous APi in ASP.NET MVC Asyncronous Methods In ASP.NET MVC 4.
Upvotes: 4