Hi
I still got problems using a windows.forms.timer.
I decleare my timer as follows:
Friend WithEvents Timer1 As System.Windows.Forms.Timer
The sub i have connected to the timer event looks like this:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False 'Paul Turn off timer
' tmrRead: call tmrRead on every occasion of timer event. If TmrReadE = True Then tmrReadSub() ' tmrStartUpSequence: call tmrStartUpSequence approx every 0.9 sec. If (tmrCounter Mod 3) = 0 And TmrStartupSequenceE = True ThentmrStartupSequenceSub()
End If ' SecTimer: call SecTimer sub approx every 0.9 sec. If (tmrCounter Mod 3) = 0 And SecTimerE = True ThenSecTimerSub()
End If ' Timer1: call timer1 sub approx every 1.8 sec. If (tmrCounter Mod 6) = 0 And Timer1E = True Thentimer1Sub()
End If 'Finally count up counter If tmrCounter = 29999 ThentmrCounter = 0
ElsetmrCounter = tmrCounter + 1
End IfTimer1.Enabled =
True 'Turn on timer End Sub
I disable the timer when entering the sub.
Then i call the subroutines:
- tmrReadSub()
- tmrStartupSequenceSub()
- SecTimerSub()
- timer1Sub()
Finally i enable the timer again.
At some occasions i can see the following in my "call stack" window:
> WindowsApplication1.UserInterface.Timer1_Tick(Object sender = {System.Windows.Forms.Timer}, System.EventArgs e = {System.EventArgs}) Line 4524 Basic
System.Windows.Forms.Timer.OnTick
System.Windows.Forms.Timer.DebuggableCallback
WindowsApplication1.PLC.ConnectToPlc() Line 266 Basic
WindowsApplication1.SystemInit.FirstInit(Boolean status = True) Line 405 Basic
WindowsApplication1.UserInterface.tmrStartupSequenceSub() Line 4562 Basic
WindowsApplication1.UserInterface.Timer1_Tick(Object sender = {System.Windows.Forms.Timer}, System.EventArgs e = {System.EventArgs}) Line 4519 Basic
System.Windows.Forms.Timer.OnTick
System.Windows.Forms.Timer.DebuggableCallback
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner
System.Windows.Forms.Application.ThreadContext.RunMessageLoop
System.Windows.Forms.Application.Run
WindowsApplication1.UserInterface.Main() Line 13 Basic
I have two calls of Timer1_Tick on my stack!
By clicking on the Timer1_Tick in the "call stack" then i can see that my variables contain different values for the two calls on the stack.
Why is this
In one of my subroutines (tmrStartupSequenceSub) i perform some "system calls" such as
- InputBox(...)
- AppendFile(...)
- And some other method calls in other modules.
My assumption was that i could call these subroutines without any problems as i have disabled my timer.
However i seems to get calls to my timer sub anyway.
Will these sub calls interfear with my system in such way that i will get calls to my timer sub even if
my timer is disabled at the moment
If there is a problem using such system calls, how shall i then prevent from getting those stacked timer calls
Regards Paul
(beginner in VB)
I