M
Microsoft
I'm trying to use threading for the first time and can't get it to work.
(VB)
In the page I've got:
Sub Page_Load( sender As Object, e As EventArgs )
dim o as new Example.Test
o.CreateThread()
End Sub
and in the Example namespace:
Public Class Test
Public Sub RunJob()
While True
WriteToLog( DateTime.UtcNow )
Thread.Sleep( 1000 * 10 )
End While
End Sub
Public Sub CreateThread()
Dim t As New Thread( AddressOf RunJob )
t.Start()
HttpContext.Current.Response.Write( t.ThreadState )
End Sub
End Class
The response is 'Unstarted' (unless I set the priority of the new thread to
AboveNormal or Highest, in which case it's 'Stopped') and nothing gets
written to the log file. If I call o.RunJob() instead of o.CreateThread() on
page loading then that routine works as I expect, i.e. the datetime is
written to the log file every 10 seconds until the request timesout after 90
seconds.
What am I doing wrong?
(VB)
In the page I've got:
Sub Page_Load( sender As Object, e As EventArgs )
dim o as new Example.Test
o.CreateThread()
End Sub
and in the Example namespace:
Public Class Test
Public Sub RunJob()
While True
WriteToLog( DateTime.UtcNow )
Thread.Sleep( 1000 * 10 )
End While
End Sub
Public Sub CreateThread()
Dim t As New Thread( AddressOf RunJob )
t.Start()
HttpContext.Current.Response.Write( t.ThreadState )
End Sub
End Class
The response is 'Unstarted' (unless I set the priority of the new thread to
AboveNormal or Highest, in which case it's 'Stopped') and nothing gets
written to the log file. If I call o.RunJob() instead of o.CreateThread() on
page loading then that routine works as I expect, i.e. the datetime is
written to the log file every 10 seconds until the request timesout after 90
seconds.
What am I doing wrong?