System.Threading.Timer将在几次后停止

时间:2014-01-22 12:47:08

标签: .net vb.net timer

我在VB.NET服务中有一个System.Threading.Timer。但是我不确定为什么计时器只运行14次然后停止。该服务仍在继续运行。这是代码:

Protected Overrides Sub OnStart(ByVal args() As String)
    Dim downloadCall As New TimerCallback(AddressOf download_tick)
    Dim timerDownload As New Timer(downloadCall, Nothing, 0, 8000)
End Sub

Private Sub download_tick(ByVal sender As Object) 
   System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\test\" & Now.ToString("yyyyMMddHHmmss") & ".txt", "")
   Dim th As New Thread(AddressOf downloadPrintJob)
   th.Start()
End Sub

Private Sub downloadPrintJob()
Try
    Using webClient As New System.Net.WebClient()
    .....

从上面的代码中,我发现每次重启服务时都会生成14个文本文件。

1 个答案:

答案 0 :(得分:0)

如果下载时间超过8秒会怎样?

我首先在作业下载时禁用计时器,然后在作业完成时重新启用计时器。