I have a problem with thread execution after calling response.redirect() in a
web form.
Basically, I want the thread to continue to work (e.g. do some long database
work) but want to redirect immediately to another page, so that the user does
not have to wait.
I tried the wollowing exemple with two webforms webform1.aspx and
webform2.aspx : WebForm1.aspx just has one button which, when clicked,
executes the following method
private void Button1_Click(object sender, System.EventArgs e)
{
Server.ScriptTimeout = 60; // One minute
Response.Redirect("WebForm2.aspx",false);
Response.Flush();
Response.Close();
Thread.Sleep(10000); // Simulate the work to do
}
When WebForm1 Button1 is clicked, the false option in the Response.Redirect
method says that thread execution should continue. Then, as Response.Flush()
and Response.Close() are called, the Redirect should take place immediatly.
However, when I try (under IIS6) the browser waits for the Sleep command to
finish and only redirects afterwards. This does not seem to be the correct
behavior.
Any ideas of what I am missing ?
Robert 3 4434
"Robert Sorger" <Ro**********@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com... I have a problem with thread execution after calling response.redirect() in a web form.
Basically, I want the thread to continue to work (e.g. do some long database work) but want to redirect immediately to another page, so that the user does not have to wait.
I tried the wollowing exemple with two webforms webform1.aspx and webform2.aspx : WebForm1.aspx just has one button which, when clicked, executes the following method
private void Button1_Click(object sender, System.EventArgs e) { Server.ScriptTimeout = 60; // One minute Response.Redirect("WebForm2.aspx",false); Response.Flush(); Response.Close();
Thread.Sleep(10000); // Simulate the work to do }
When WebForm1 Button1 is clicked, the false option in the Response.Redirect method says that thread execution should continue. Then, as Response.Flush() and Response.Close() are called, the Redirect should take place immediatly.
However, when I try (under IIS6) the browser waits for the Sleep command to finish and only redirects afterwards. This does not seem to be the correct behavior.
Any ideas of what I am missing ?
For one thing, you don't want to tie up an ASP.NET thread with database
work. The thread will not be available for other requests. Instead, queue
work like this to a worker process which is outside of the ASP.NET
application (perhaps in a Windows Service).
Look at the following for ways to do what you're trying to do.
Indicating Progress http://msdn.microsoft.com/library/de...pplication.asp
Make a Progress Indicator For Slow-Loading Pages
( http://www.aspnetpro.com/NewsletterA...200308bm_l.asp)
DESIGN PATTERNS: Asynchronous Wait State Pattern in ASP.NET http://msdn.microsoft.com/msdnmag/is...s/default.aspx
John Saunders
Hey Robert.
The reason why you aren't getting what you want is because ot the
Thread.Sleep().
Even if you called Response.Redirect the runtime MUST end the current
function.
Only after that Response.Flush will take effect. And because Thread.Sleep
freezes the current thread you end up waiting for it to finish.
Kirill Osipov
"Robert Sorger" <Ro**********@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com... I have a problem with thread execution after calling response.redirect() in a web form.
Basically, I want the thread to continue to work (e.g. do some long database work) but want to redirect immediately to another page, so that the user does not have to wait.
I tried the wollowing exemple with two webforms webform1.aspx and webform2.aspx : WebForm1.aspx just has one button which, when clicked, executes the following method
private void Button1_Click(object sender, System.EventArgs e) { Server.ScriptTimeout = 60; // One minute Response.Redirect("WebForm2.aspx",false); Response.Flush(); Response.Close();
Thread.Sleep(10000); // Simulate the work to do }
When WebForm1 Button1 is clicked, the false option in the Response.Redirect method says that thread execution should continue. Then, as Response.Flush() and Response.Close() are called, the Redirect should take place immediatly.
However, when I try (under IIS6) the browser waits for the Sleep command to finish and only redirects afterwards. This does not seem to be the correct behavior.
Any ideas of what I am missing ? Robert
Thanks!
"John Saunders" wrote: "Robert Sorger" <Ro**********@discussions.microsoft.com> wrote in message news:85**********************************@microsof t.com...I have a problem with thread execution after calling response.redirect() in a web form.
Basically, I want the thread to continue to work (e.g. do some long database work) but want to redirect immediately to another page, so that the user does not have to wait.
I tried the wollowing exemple with two webforms webform1.aspx and webform2.aspx : WebForm1.aspx just has one button which, when clicked, executes the following method
private void Button1_Click(object sender, System.EventArgs e) { Server.ScriptTimeout = 60; // One minute Response.Redirect("WebForm2.aspx",false); Response.Flush(); Response.Close();
Thread.Sleep(10000); // Simulate the work to do }
When WebForm1 Button1 is clicked, the false option in the Response.Redirect method says that thread execution should continue. Then, as Response.Flush() and Response.Close() are called, the Redirect should take place immediatly.
However, when I try (under IIS6) the browser waits for the Sleep command to finish and only redirects afterwards. This does not seem to be the correct behavior.
Any ideas of what I am missing ?
For one thing, you don't want to tie up an ASP.NET thread with database work. The thread will not be available for other requests. Instead, queue work like this to a worker process which is outside of the ASP.NET application (perhaps in a Windows Service).
Look at the following for ways to do what you're trying to do. Indicating Progress http://msdn.microsoft.com/library/de...pplication.asp
Make a Progress Indicator For Slow-Loading Pages (http://www.aspnetpro.com/NewsletterA...200308bm_l.asp) DESIGN PATTERNS: Asynchronous Wait State Pattern in ASP.NET http://msdn.microsoft.com/msdnmag/is...s/default.aspx
John Saunders This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kerri |
last post by:
Hi,
I have do some Redirects in my applitcaion.
For example, when the use rhas logged in successfully I
redirect them to a different page.
In my Redirect all I was doing was a..
...
|
by: VB Programmer |
last post by:
I have a default.aspx page that simply does this (in the "Try" block):
Response.Redirect("MyStartPage.aspx")
I keep getting this exception on this line:
"System.Threading.ThreadAbortException:...
|
by: Vi |
last post by:
Hi,
I have a try block in which I execute a Page.Response.Redirect("myPage.aspx");
This statement always generates the exception: "Thread was being aborted"
and the execution continues in the...
|
by: Mantorok |
last post by:
Hi all
When I start a new thread that tries to call:
HttpContext.Current.Response.Redirect()
It fails as Current returns null, is there anyway to access the current
httpcontext from within...
|
by: MikeM |
last post by:
We are getting a behavior on a Response.Redirect("SomeUrl", True) that I'm
hoping someone can explain. This all refers to the code snip at the end. By
the way, this is all VB ASP.NET v1.0 code.
...
|
by: Niggy |
last post by:
I get an error - any help appreciated.
System.Threading.ThreadAbortException: Thread was being aborted. at
System.Threading.Thread.AbortInternal() at
System.Threading.Thread.Abort(Object...
|
by: venner |
last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET
2.0. The website makes use of a central authentication service (CAS)
provided at the university I work for. Each page checks...
|
by: =?Utf-8?B?cGI=?= |
last post by:
I am having trouble doing a redirect in an async asp.net implemention.
Most of the time it works, but when it doesn't it just "hangs", the browser
never gets any return page. If I run it under the...
|
by: seanmatthewwalsh |
last post by:
Hi
I have a page (default.aspx) that pulls it's HTML from a database.
I then have a "content management" page (editpage.aspx) that allows
the user to edit the HTML in the database.
When the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |