Multithreading and ASP.net

S

Shathish

Hai
i am trying to write a multithreading asp.net application
this is the code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Try
DisplayLoadingMovie()
StartThread()
Catch ex As Exception

End Try
End If
End Sub

Private Sub GetPlaceHolders()
Try
Thread.Sleep(7000)
Dim strScript As String
strScript = "<script language=javascript>"
strScript &=
"window.parent.fra2.location.href='AfterLoading.aspx?Finished=Y';"
strScript &= "</script>"
Response.Write(strScript)
Catch ex As Exception

End Try

End Sub

Private Sub DisplayLoadingMovie()
Dim strScript As String
strScript = "<script language=javascript>"
strScript &=
"window.parent.fra2.location.href='Loading.aspx';"
strScript &= "</script>"
Response.Write(strScript)
End Sub

Private Sub StartThread()
Dim dlgThreadStart As ThreadStart = New ThreadStart(AddressOf
GetPlaceHolders)
Dim workerThread As Thread = New Thread(dlgThreadStart)
workerThread.Start()
End Sub

but wheni try to run the program the GetPlaceHolders method generates
a HttpException saying "Response is not available in this context"
Anyone got any idea how to work around the problem
 
M

Marina

That is because creating another thread, means this thread can't have access
to anything on the page. The original request is still executing - but this
other threat is off on its own, doing work concurrently with the other one.
This is because I can't imagine that asp.net would be able to reconcile all
threads spawned from the original request, and know when it was time to send
the page back.

What is it you are trying to accomplish with multiple threads?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top