473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

redirect and thread execution

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

Nov 18 '05 #1
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
Nov 18 '05 #2
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

Nov 18 '05 #3

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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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.. ...
1
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:...
1
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...
8
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...
1
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. ...
10
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...
5
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...
12
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.