run code on background

  • Thread starter Thread starter Jurgen Oerlemans
  • Start date Start date
J

Jurgen Oerlemans

Hello

I have a program for which I want to see from a distance if it has been
started.
I made a timer which is enabled when the program is started.
Code in the timer:
Label_Again:

txtWaitRun.Text = "R"
Threading.Thread.Sleep(300)
txtWaitRun.Text = "Ru"
Threading.Thread.Sleep(300)
txtWaitRun.Text = "Run"
Threading.Thread.Sleep(300)
txtWaitRun.Text = "Runn"
Threading.Thread.Sleep(300)
txtWaitRun.Text = "Runni"
Threading.Thread.Sleep(300)
txtWaitRun.Text = "Runnin"
Threading.Thread.Sleep(300)
txtWaitRun.Text = "Running"
Threading.Thread.Sleep(300)

GoTo Label_Again

When this timer starts:
1: I do not see the text of txtWaitRun change
2: The rest of the program doesn't start ofcourse because the timer is
never ready.

How can I run this code permanently on the background?
Why doesn't the text change?

Best regards, Jurgen
 
Hi Jurgen,

Not the nicest code with that goto (but it is for testing I asume), however
your problem is that when a method is run it has no contact with the UI, to
try that you can set after every wait a me.refresh (Do not set it in your
production version it is not for nothing that it is not done forever)

I hope this helps?

Cor
 
Hello Cor,

The refresh I found out already and that helps. But the problem is that the
loop is never completed so the program will not continu with the rest of the
code after the timer.

Jurgen
 
Look into using threads, that way you can run your code and allow the main
application to run.

HTH
John
 
Hi Jurgen,

There are 4 timers, are you using the
system.timers.timer
for this most people start with taking the
system.forms.form.timer

And than not using that crazy loop, only when it is firing you can use that.
And before somebody starts to point me on that have a look at multithreading
for this, however make it first working with a
\\\
applications.doevents as well in your code.
///

I think that it is better that you switch to the newsgroup

microsoft.public.dotnet.languages.vb

(There are more persons than in this newsgroup who answers VBNet language
questions)

Cor
 
Back
Top