Organizational Research By

Surprising Reserch Topic

thread.sleep in

I'm simulating the comet live feed protocol for my site, so in my controller I'm adding

while(nothing_new && before_timeout){

but I noticed the whole website got slow after I added this feature. After debugging I concluded that when I call Thread.Sleep all the threads, even in other requests, are being blocked.

Why does Thread.Sleep block all threads, not only the current, and how to deal with an issue like this?


asked May 9, 2015 in Asp.Net by rajesh
0 votes

Related Hot Questions

1 Answer

0 votes
What @Servy said is correct. In addition to his answer I would like to throw my 2 cents. I bet you are using ASP.NET Sessions and you are sending parallel requests from the same session (for example you are sending multiple AJAX requests). Except that the ASP.NET Session is not thread safe and you cannot have parallel requests from the same session. ASP.NET will simply serialize the calls and execute them sequentially.

That's why you are observing this blocking. It will block only requests from the same ASP.NET Session. If you send an HTTP requests from a different session it won't block. This behavior is by design and you can read more about it here.

ASP.NET Sessions are like a cancer and I recommend you disabling them as soon as you find out that they are being used in a web application:

No more queuing. Now you've got a scalable application.
answered May 9, 2015 by rajesh