Pausing ASP.Net 2.0 Page
January 4, 2007
posted by Rick Barber
For the most part, web pages load sequentially where pieces of code execute one right after the other. Sometimes you need a page to stop for a predetermined amount of time while it waits for other tasks to complete. An example of this is a web page that sends an email outside of your network which needs to wait while the email is sent, processed by the spam filter, checked by the anti-virus, and then processed by the mail server to show up in a mail box before the web page indicates whether the message was received. As you know, this process can take over 30 seconds.
Before ASP.Net 2.0 it was possible to implement something like this, but it was either involved writing a bunch of code or using a third party component. Now with ASP.Net 2.0 you can use the following:
System.Threading.Thread.Sleep(xxx)
This stops execution of the page for xxx number of milliseconds, so a value of 120000 would pause page execution for 2 minutes.
One thing to keep in mind is that this only pauses execution of the page and has no affect on IIS values. IIS is generallly set to timeout after two minutes so you will get a timeout error if you don't also adjust the value for the web site in IIS. In my testing I've found that three minutes is about the maximum that you should consider doing this for. If you need to do it for a longer time then you should try looking at the problem you are trying to solve from a different angle.












