Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Timer problem...

kern68kern68 Posts: 85Member
I am trying to use the System.Windows.Forms.Timer class, but can not get it to work. The timer's interval is set to 100 ms. I have created several to handle the Timer's activity.

[code]
Dim TimerCounter As Integer
...StartTimer()
TimerCounter = 0
Me.ABTimer.Enabled = True
...StopTimer()
Me.ABTimer.Enabled = False
...GetTimer()
Me.BackupTime.Text = TimerCounter
...Timer_Tick(...)
TimerCounter = TimerCounter + 1
...BA()
Me.StartTimer()
.
. REM Stuff that takes time.
.
Me.StopTimer()
Me.GetTimer()
[/code]

From my interpretation Timer_Tick starts working on, in this case, 100ms intervals after ABTimer.Enabled = True, but the variable TimerCounter stays at zero.

Does anyone have any idea why this won't work?

Thanks for the assistance,

GeoK
[italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]

Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I am trying to use the System.Windows.Forms.Timer class, but can not
    : get it to work. The timer's interval is set to 100 ms. I have
    : created several to handle the Timer's activity.
    :
    : [code]:
    : Dim TimerCounter As Integer
    : ...StartTimer()
    : TimerCounter = 0
    : Me.ABTimer.Enabled = True
    : ...StopTimer()
    : Me.ABTimer.Enabled = False
    : ...GetTimer()
    : Me.BackupTime.Text = TimerCounter
    : ...Timer_Tick(...)
    : TimerCounter = TimerCounter + 1
    : ...BA()
    : Me.StartTimer()
    : .
    : . REM Stuff that takes time.
    : .
    : Me.StopTimer()
    : Me.GetTimer()
    : [/code]:
    :
    : From my interpretation Timer_Tick starts working on, in this case,
    : 100ms intervals after ABTimer.Enabled = True, but the variable
    : TimerCounter stays at zero.
    :
    : Does anyone have any idea why this won't work?
    :
    : Thanks for the assistance,
    :
    : GeoK
    : [italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]

    The timer will not interrupt running code.
    So if you are in the REM stuff block, then it will run completely until the end of the function. Only at the end of all functions will the Timer start firing (the timer will still count while running code, it just won't fire until the code is done running).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • kern68kern68 Posts: 85Member
    : : I am trying to use the System.Windows.Forms.Timer class, but can not
    : : get it to work. The timer's interval is set to 100 ms. I have
    : : created several to handle the Timer's activity.
    : :
    : : [code]: :
    : : Dim TimerCounter As Integer
    : : ...StartTimer()
    : : TimerCounter = 0
    : : Me.ABTimer.Enabled = True
    : : ...StopTimer()
    : : Me.ABTimer.Enabled = False
    : : ...GetTimer()
    : : Me.BackupTime.Text = TimerCounter
    : : ...Timer_Tick(...)
    : : TimerCounter = TimerCounter + 1
    : : ...BA()
    : : Me.StartTimer()
    : : .
    : : . REM Stuff that takes time.
    : : .
    : : Me.StopTimer()
    : : Me.GetTimer()
    : : [/code]: :
    : :
    : : From my interpretation Timer_Tick starts working on, in this case,
    : : 100ms intervals after ABTimer.Enabled = True, but the variable
    : : TimerCounter stays at zero.
    : :
    : : Does anyone have any idea why this won't work?
    : :
    : : Thanks for the assistance,
    : :
    : : GeoK
    : : [italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]
    :
    : The timer will not interrupt running code.
    : So if you are in the REM stuff block, then it will run completely
    : until the end of the function. Only at the end of all functions will
    : the Timer start firing (the timer will still count while running
    : code, it just won't fire until the code is done running).
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

    Okay, I understand that the timer will not interrupt running code.

    Pardon my lack of completeness. The reference to Me.StopTimer() and Me.GetTimer() are the final lines in the subroutine before END SUB.

    Thanks,
    GeoK
    [italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    :
    : Okay, I understand that the timer will not interrupt running code.
    :
    : Pardon my lack of completeness. The reference to Me.StopTimer() and
    : Me.GetTimer() are the final lines in the subroutine before END SUB.
    :
    : Thanks,
    : GeoK
    : [italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]

    Ok that helps. I think I understand the code now.
    What happens is the following:

    1) You enable the timer
    2) You are running the code in REM
    3) The timer fires somewhere in the REM code, but it won't interrupt it
    4) At the end of the REM code, your timer still has an Event pending
    5) You stop and disable the timer. This cancels the pending event
    6) You get the amount of times it has been fired. This is ofcourse 0.
    7) End of sub

    To time your code, query the computer time at the start and at the end and calculate the difference in ms between those (or in seconds, etc).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.