Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async Function Thread.Sleep in Web Application

I maintain a ASP.NET web application that causes a user's network connection to reset for several seconds when it executes a procedure. Therefore, the page request times out on the user's end as they never receive the web application's response (the connection dies before it gets the response packet).

To resolve this situation, I was contemplating having the ASP.NET page execute an asynchronous function that incorporates a Thread.Sleep(5000); // sleep for 5 seconds before executing the connection reset This way, the browser has 5 seconds to receive the page's response before their connection resets.

I have concerns with using Thread.Sleep and asynchronous functions in ASP.NET though. I've never attempted to do it before, so I'm unsure of the potential problems it may cause. Does anyone see potential problems with starting an asynchronous thread that contains a Thread.Sleep in an ASP.NET application? If so, can you think of a better solution?

like image 810
regex Avatar asked Sep 08 '10 22:09

regex


1 Answers

Placing Thread.Sleep in an asynchronous method can contribute to ThreadPool Starvation, as it blocks one of a limited number of threads for several seconds - that thread could be off servicing client requests.

Instead, why not create a timer that fires after five seconds? Same effect, just register your delayed work in the timer's event.

like image 164
FacticiusVir Avatar answered Sep 23 '22 13:09

FacticiusVir