G
Guest
Hi.
I Have a VB.Net Windows Application that starts up using Sub Main.
It's a program that runs in the background and checks something every minute.
I use a Timer to accomplish this and it's working but to get it to work I
use a boolean variable (mbLoop) and the program runs until mbLoop is set to
False.
Do While mbLoop
'
Loop
The problem is that I see this program always using 25% of CPU. I know it's
the looping that's going on that's causing this but I don't know how to keep
the program running without it. I tried taking it out but it just executed
the code in Sub Main and when it hit End Sub the program ended.
Here's my code:
Imports System.Threading 'Timer
Module modMain
Dim WithEvents moTimer As System.Timers.Timer
Sub Main()
moTimer = New System.Timers.Timer(60000)
moTimer.AutoReset = True
moTimer.Enabled = True
'*** Will continue working as long as mbLoop is set to True
Do While mbLoop
'
Loop
End Sub
Sub OnTimedEvent(ByVal Source As Object, _
ByVal e As System.Timers.ElapsedEventArgs)
Handles
moTimer.Elapsed
'
' All my code here is executed every 60 seconds
'
End Sub
Any suggestions will be greatly appreciated!
Rita
I Have a VB.Net Windows Application that starts up using Sub Main.
It's a program that runs in the background and checks something every minute.
I use a Timer to accomplish this and it's working but to get it to work I
use a boolean variable (mbLoop) and the program runs until mbLoop is set to
False.
Do While mbLoop
'
Loop
The problem is that I see this program always using 25% of CPU. I know it's
the looping that's going on that's causing this but I don't know how to keep
the program running without it. I tried taking it out but it just executed
the code in Sub Main and when it hit End Sub the program ended.
Here's my code:
Imports System.Threading 'Timer
Module modMain
Dim WithEvents moTimer As System.Timers.Timer
Sub Main()
moTimer = New System.Timers.Timer(60000)
moTimer.AutoReset = True
moTimer.Enabled = True
'*** Will continue working as long as mbLoop is set to True
Do While mbLoop
'
Loop
End Sub
Sub OnTimedEvent(ByVal Source As Object, _
ByVal e As System.Timers.ElapsedEventArgs)
Handles
moTimer.Elapsed
'
' All my code here is executed every 60 seconds
'
End Sub
Any suggestions will be greatly appreciated!
Rita