Why does this threading approach not work?
Posted
by Tomas Lycken
on Stack Overflow
See other posts from Stack Overflow
or by Tomas Lycken
Published on 2010-06-16T09:51:05Z
Indexed on
2010/06/16
9:52 UTC
Read the original article
Hit count: 228
multithreading
|asp.net-2.0
I have a wierd problem with threading in an ASP.NET application. For some reason, when I run the code in the request thread, everything works as expected. But when I run it in a separate thread, nothing happens.
This is verified by calling the below handler with the three flags "on", "off" and "larma" respectively - in the two first cases everything works, but in the latter nothing happens.
What am I doing wrong here?
In the web project I have a generic handler with the following code:
If task = "on" Then
Alarm.StartaLarm(personId)
context.Response.Write("Larmet är PÅ")
ElseIf task = "off" Then
Alarm.StoppaLarm(personId)
context.Response.Write("Larmet är AV")
ElseIf task = "larma" Then
Alarm.Larma(personId)
context.Response.Write("Larmar... (stängs av automagiskt)")
Else
context.Response.Write("inget hände - task: " & task)
End If
The Alarm
class has the following methods:
Private Shared Sub Larma_Thread(ByVal personId As Integer)
StartaLarm(personId)
Thread.Sleep(1000 * 30)
StoppaLarm(personId)
End Sub
Public Shared Sub StartaLarm(ByVal personId As Integer)
SandSMS(True, personId)
End Sub
Public Shared Sub StoppaLarm(ByVal personId As Integer)
SandSMS(False, personId)
End Sub
Public Shared Sub SandSMS(ByVal setOn As Boolean, ByVal personId As Integer)
...
End Sub
© Stack Overflow or respective owner