keep program running

  • Thread starter William LaMartin
  • 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.
 
C

Cor Ligthert [MVP]

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
 
H

Herfried K. Wagner [MVP]

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()'.
 
W

William LaMartin

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.
 
W

William LaMartin

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
 
W

William LaMartin

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.
 
C

Cor Ligthert [MVP]

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
 
H

Herfried K. Wagner [MVP]

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.
 
H

Herfried K. Wagner [MVP]

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.
 
W

William LaMartin

There is no application object if I only have a module in my project as best
I can tell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top