System.Timers.Timer Elapsed event executing after timer.Stop() is called

前端 未结 3 1374
面向向阳花
面向向阳花 2020-11-30 12:11

Background: I have a timer that I am using to keep track of how long it has been since the serialPort DataReceived event has been fired. I am creating my ow

3条回答
  •  清歌不尽
    2020-11-30 13:04

    I did a pause in timer with this code. for me that works.

    Private cTimer As New System.Timers.Timer
    Private Sub inittimer()
        cTimer.AutoReset = True
        cTimer.Interval = 1000
        AddHandler cTimer.Elapsed, AddressOf cTimerTick
        cTimer.Enabled = True
    End Sub
    
    Private Sub cTimerTick()
        If cTimer.AutoReset = True Then
           'do your code if not paused by autoreset false
        End If
    End Sub
    

提交回复
热议问题