keep program running

  • Thread starter Thread starter William LaMartin
  • Start date Start date
W

William LaMartin

If I have a Windows application with no form--only a module that starts with
sub main and which has a system timer, in the elapsed event of which I want
to run some code, how can I keep this program from running through the sub
main code and then closing without ever firing the timer?

I can put

Do While 3 <> 2

Loop

at the end of the sub main code and that seems to work, but there must be a
better way.
 
William,

As you tell it there is not any code needed. Can you rephrase.

Probably it is a loop with a threading.thread.sleep in it.

However there your text does not tell how your program stops.

Cor
 
William LaMartin said:
If I have a Windows application with no form--only a module that starts
with sub main and which has a system timer, in the elapsed event of which
I want to run some code, how can I keep this program from running through
the sub main code and then closing without ever firing the timer?

'Application.Run()'.
 
A process that fires at regular intervals based on a timer. I tried to use
a Windows service to do this but found that it ran in a different account
than did the user so it had no knowledge of things like key strokes, etc
that the user was making.
 
I am trying to run process that fires at regular intervals based on a timer.
I tried to use a Windows service to do this but found that it ran in a
different account than did the user so it had no knowledge of things like
key strokes, etc that the user was making.

Here is the sub main code. All of the work is actually done in the timer
code.

Public Sub Main()

MyTimer1.Interval = 50
MyTimer1.Enabled = True
MyTimer2.Interval = 10000
MyTimer2.Enabled = True
'MsgBox("started") 'this will keep the program running if not
clicked on
'here is another method of keeping the program running to allow the
timers to fire.
Do While 3 <> 2

Loop

End Sub
 
I can not use a Windows Service for this application. I tried. The service
runs in an account that knows nothing about certain things the user is doing
like keystrokes.
 
Do
Application.doevents
threading.thread.sleep(milliseconds) ' something as 3000
Loop

This will stop the program if the user clickes the close box in top of the
form.
If you let it always go it will eat your complete processing time.

I hope this helps,

Cor
 
William LaMartin said:
I do not understand your answer.

Simply call 'Application.Run' at the end of your 'Sub Main'. This will
prevent the Windows Application from terminating when the code inside 'Sub
Main' has been executed.
 
William LaMartin said:
I am trying to run process that fires at regular intervals based on a
timer.

Which timer class are you using? Note that 'System.Windows.Forms.Timer' is
only intended for use on a form.
 
There is no application object if I only have a module in my project as best
I can tell.
 
Back
Top