global.asaxを使用します。global.asax
では、アプリケーションの起動時にメソッドApplication_Startが呼び出されます。
Application_Start メソッドでスレッドを実行し、Application_Endメソッドでこのスレッドを終了します。<br /> サンプル コードは次のとおりです。
Public Class job
Public Property StopThread As Boolean = False
Public Sub DoJob()
Do While Not StopThread
If Now.Minute = 0 Then
'Do Sync Work
End If
Threading.Thread.Sleep(1000 * 60)
Loop
End Sub
End Class
Public Class Global_asax
Inherits HttpApplication
Private j As job
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
j = New job
Dim JobThread As System.Threading.Thread
JobThread = New Threading.Thread(AddressOf j.DoJob)
JobThread.Start()
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
j.StopThread = True
End Sub
End Class