Threading Error?


A

al

Greeting,

I have this sub in a page that runs a thread to change direction of a
page then redirects to a new page(please wait message page)which
checks for a global flag and returns to previous page if true. The
problem when I assign thread priority to highest, it just works like a
dream, otherwise, it produces an error:

----The type System.Web.HttpException
in Assembly System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a is not
marked as serializable-----



Code:
*****In default page:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim NewThread As Thread = New Thread(AddressOf
ChangeDirection)

NewThread.Priority = ThreadPriority.Normal ''''********this
produces and error unless put to highest

NewThread.Start()

Response.Redirect("/Testing/WaitPage.aspx")

End Sub


Public Sub ChangeDirection()

Response.Write("<script>document.dir=""rtl""</script>")

Session("Finished") = True

End Sub
End Class


***********In WaitPage.aspx:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Session("Finished") = False Then

Response.Write("<META HTTP-EQUIV=Refresh CONTENT=""3; URL="">
")
Label1.Text = "Processing. . ."

Else

Label1.Text = "Finished!"
Response.Write("<script>document.location.replace(""default.aspx"")</>")
End If


End Sub

MTIA,
Grawsha
 
Ad

Advertisements

W

William

On 4 Apr 2004 12:10:04 -0700, (e-mail address removed) (al) typed and posted to
microsoft.public.dotnet.framework.aspnet:

I'm no expert but it might have something to do with the context of the thread.
The fact that it's being called from the ASP.NET worker thread. Being web
based the thread would have to execute as fast as it can so it would not tie up
valuable resources or something to that effect.

My $0.02
Will
 
Ad

Advertisements

A

Alvin Bruney [MVP]

Nope. OP has violated a sacred threading rule. If it is an NT based system
it could work for a while but it is guaranteed to fail. A thread should not
touch objects owned by the main thread. The response object and the session
objects are owned by the main thread and OP is using it in the child thread.
The easiest way around this is to pass in a reference to the response and
session objects to the child thread. Or, replace the session object with a
static variable assuming that the response.write method doesn't do any real
work. There would need to be synchronization access to this variable
ofcourse.
 

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