I have a program that runs as a service so there is no UI. It checks for a file every 30 seconds and does it thing to the file if it finds one, if not it waits for another 30 seconds. I have the timer portion worked out, what I am having problems with is keeping the program from exiting.
The sub main is pretty much
Dim timeCB As TimerCallback = AddressOf ProcessDocs
Dim t As Timer = New Timer(AddressOf ProcessDocs, Nothing, 0, 1000)
Right now it loads and thens exits. I have put different things in the program such as a pause sub I have:
Public Sub Pause(ByRef iSeconds As Short)
Dim lStart As Integer
lStart = VB.Timer() ' Set start time.
Do While VB.Timer() < lStart + iSeconds And Not gbStop
System.Windows.Forms.Application.DoEvents() ' Yield to other processes.
Have set it to 60 seconds and see that it works fine, of course after a minute it exists.
The question is: What is the most efficient way of keeping the program from exiting? Right now I have an infinite loop with a pause in the body.
There must be a more elegant, less processor intensive way of doing this, maybe I am being picking, but having to run two timers to get this thing to work makes me think I am just missing something. Any ideas? Remember the entire project consists of a module, there is no UI because it will be ran from a service. At least if I did a message box nobody would every click on it.