私は特定のユーザーによって生成されたつぶやきを10分ごとに読み取るasp.net mvcアプリケーションを作成しました。私はこの作業をタイマーで行います。タイマーは2〜5回完全に実行され、タイマーは例外またはエラーなしで停止します。なぜ私のasp.net mvcタイマーが停止しますか?
誰かがこれが起こる理由を知っていますか?タイマを停止するまで、常に実行するように設定する方法はありますか?
ここでタイマー設定やタイマーのハンドラ:
Public Shared Function Start()
Dim db As New EnubexDbContext
Dim provider As CultureInfo = CultureInfo.InvariantCulture
Dim tiempo As Double = Convert.ToDouble(db.ParametrosGenerales.Where(Function(pg) pg.sDescripcionParametroGeneral = "frecuenciaSeekerTwitterTimer").Select(Function(pg) pg.sValorParametroGeneral).FirstOrDefault())
If Not IsNothing(tiempo) Then
timer = New Timer(tiempo)
If Not IsNothing(timer) Then
ApplicationLog.EscribirActividad("Se creo el objeto timer")
End If
Try
AddHandler timer.Elapsed, New ElapsedEventHandler(AddressOf Handler)
ApplicationLog.EscribirActividad("Se agregó el handler")
timer.Enabled = True
If Not IsNothing(timer) Then
ApplicationLog.EscribirActividad("Se activó el timer")
End If
Return (0)
Catch ex As Exception
ApplicationLog.EscribirExcepctionLog(ex)
Return (1)
End Try
Else
Return (1)
End If
End Function
Shared Async Sub Handler(ByVal sender As Object, ByVal e As ElapsedEventArgs)
ApplicationLog.EscribirActividad("Empezando búsqueda")
Try
Await SeekTwitter()
ApplicationLog.EscribirActividad("Terminando búsqueda")
Catch ex As Exception
ApplicationLog.EscribirExcepctionLog(ex)
End Try
End Sub
これはおそらく、AppPoolがリサイクルしてタイマーを破棄しているためです。 'Start()'はどこから呼び出されますか? –
ASP.NETでバックグラウンドプロセスを実行しないでください。あなたはうんざりします。 Scott Hanselmanは彼のブログ[here](http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx)でそれについて議論します。 – mason