Perform tasks with delay, without delaying web response (ASP.NET)
Posted
by Tomas Lycken
on Stack Overflow
See other posts from Stack Overflow
or by Tomas Lycken
Published on 2010-06-14T12:30:47Z
Indexed on
2010/06/14
13:32 UTC
Read the original article
Hit count: 140
I'm working on a feature that needs to send two text messages with a 30 second delay, and it is crucial that both text messages are sent. Currently, this feature is built with ajax requests, that are sent with a 30 second javascript delay, but since this requires the user to have his browser open and left on the same page for at least 30 seconds, it is not a method I like. Instead, I have tried to solve this with threading.
This is what I've done:
Public Shared Sub Larma()
Dim thread As New System.Threading.Thread(AddressOf Larma_Thread)
thread.Start()
End Sub
Private Shared Sub Larma_Thread()
StartaLarm()
Thread.Sleep(1000 * 30)
StoppaLarm()
End Sub
A web handler calls Larma(), and StartaLarm() and StoppaLarm() are the methods that send the first and second text messages respectively. However, I only get the first text message delivered - the second is never sent.
Am I doing something wrong here? I have no deep understanding of how threading works in ASP.NET, so please let me know how to accomplish this.
© Stack Overflow or respective owner