Redirect in a new thread

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

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 a new thread?

Thanks
Kev
 
Typically when you spawn another thread, the original request thread will
have completed and no longer be around.

If you are blocking on the request thread until your spawned is completed,
could you just not use a return value from your spawned thread?

bill
 
Hi Bill

What I basically want to do is redirect the user to an aspx, but at the
server side I want it to wait until a response has been posted back from the
client side before continuing execution.

Any ideas?

Thanks
Kev
 
I am not exactly sure what you are wanting to do.

The user makes a request to Page1.aspx.
Page1.aspx starts ThreadA.
ThreadA waits until Page1.aspx has been posted from the same user.
ThreadA starts processing.

bill
 
I have a class that redirects the user to a page, but I want the class to
stay "alive" until the page has been posted from the user.

As you know the Response.Redirect stops all execution, the behaviour I want
is for the page to still post but for the execution to continue.

HTH
Kev
 
Response.Redirect( newPage, false ) -- Will continue execution and just add
the Redirect header to the outgoing request.

Response.Redirect( newPage, true ) -- Will cause a thread abort exception
and the Redirect header to the outgoing request.

Can you not place your class in Session?

I am still not sure where the spawned thread is coming in.

bill
 
Hi bill

Well, here is a typical example of what I want to do...

public class PageShower
{
public void ShowAndWait()
{
// Redirect then wake up when required
HttpContext.Current.Response.Redirect("wizard.aspx", false);

// Sleep
Sleep();
}
}

I want the redirect to happen while the class waits, it will then be
subsequently woken up later on. Ignore the other thread for now, I though
threading may be able to provide a solution on this matter.

HTH
Kev
 
I guess I am being hard headed. Or just dumb, but I still don't see what
you are trying to accomplish.

Why don't you take you PageShower class and place it into session. Then
after the page redirects, you can pull the same object out of Session and
call another method.

Remove the Sleep method from the ShowAndWait method.

One of the rules I go with on Threading, it you can't think of a good reason
why you are using threading, then don't. If your only reason is, I thought
"it" would be better, it probably isn't.

HTH,

bill
 
Back
Top