How do i interupt a loop?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

(VB.NET 2003)
I have a simulation that runs in a loop. I would like to give the user acces
to interrupt and cancel the simulation.
At the start of each loop, I check a global variable which can be set to
false by clicking a 'cancel' button but the operating system gives so much
resources to my simulation, that it does not allow me (the user) to click the
button untill after the simultion.

How can I introduce a short pause or something that will allow the button to
be clicked if needed?

I have a similar problem with a splash screen form that I show during
startup by using splashScreenForm.show(), but the processor is so busy with
the code that follows, that the form does not display untill after all is
done (I actually want to show the splashscreen while the PC is busy loading
data etc.)

Any help?
 
Are you running the simualation in the same thread that UI runs?
if so you can tey Application.DoEvents()...

On the other hand it is better to run the simulation in the separate thread,
then UI will be respond to the click.
However you will have to synchronize the access to that global variable
 
Excellent Thanks! DoEvents is what I was after. At the moment I am still
avoiding the manipulation of threads!
 
Paul Naude said:
Excellent Thanks! DoEvents is what I was after. At the moment I am still
avoiding the manipulation of threads!

You do well; multithreading should be avoided unless the task is otherwise
*impossible*
 
Paul Naude said:
You do well; multithreading should be avoided unless the task is
otherwise *impossible*

WOW!!! That is quite a statement. Care to embellish on that a little
 
Brad said:
You do well; multithreading should be avoided unless the task is otherwise
*impossible*

So you think re-entrancy (which is what you get with
Application.DoEvents()) is easier to handle than multi-threading? I'm
afraid I disagree there.
 
....and not take advantage of the trend towards multi-core processors - where
multi-threading will be key to improving your application performance.

Cheers,

Stu
 
Back
Top