Server.Transfer fails because httpcontext.current = nothing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm using Threads, and when I try to do Server.Transfer, I recieved an
error. (child object does not exist...)

My Code:

Dim t As New Thread(AddressOf Hilo)

Private Sub Hilo()
Thread.Sleep(1000)
Server.Transfer("Index.aspx")
end Sub

In Page Load I use:
t.Start()

The Thread works fine, but fails in Server.Transfer. I notice
Httpcontext.current is nothing inside "Private Sub Hilo()", but it isn't in
PageLoad, so the sentence Server.Transfer fails.


I've tried to declare a httpcontext variable and set the value of
httpcontext.current in page load.
i.e. Dim HT as httpcontext

And inside PageLoad:
HT = httpcontext.current.

It works in pageload, but inside Sub Hilo, HT is nothing as well.

Any Idea?
 
Basically you launch a new thread that waits (and the HTTP requests ends
during this time) and once the HTTP request is over you want to transfer the
flow control for the "current" request to some other page (but the request
is already over so it fails).

What do you want to do ?

Note also that before investigating multithreading you also have built-in
mechanism in ASP.NET that should be likely favored over custom
multithreading (for example asynchronous web service calls).
 
your page sent its response and its context was released before the
thread completed. in prerender you should do a join back to the thread.
this way the thread an send data to the browser.

-- bruce (sqlwork.com)
 
The Page I'm loading has an <IFRAME> tag with a form inside which is submited
automatically in OnLoad Event, just after its fields are filled with hidden
values.

The form is submitied to an external server, and this external server
inserts a data in a database.

My page must be waiting until the data was intersed, and then, not before, I
have to do a response.redirect or server.transfer to another page.

I use a thread to be searching in the database to know when the data has
been inserted.
 
Hi Bruce,

I can't do a join back, because I need the aspx page was loaded completely,
so I use the thread in that way.

I explain you what I want to do.

The Page I'm loading has an <IFRAME> tag with a form inside which is
submited automatically in OnLoad Event, just after its fields are filled with
hidden values.

The form is submitied to an external server, and this external server
inserts a data in a database.

My page must be waiting until the data was intersed, and then, not before, I
have to do a response.redirect or server.transfer to another page.

I use a thread to be searching in the database to know when the data has
been inserted.
 
Back
Top