How do i interupt a loop?

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?
 
V

Vadym Stetsyak

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
 
G

Guest

Excellent Thanks! DoEvents is what I was after. At the moment I am still
avoiding the manipulation of threads!
 
G

Guest

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

chris martin

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
 
J

Jon Skeet [C# MVP]

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

Guest

....and not take advantage of the trend towards multi-core processors - where
multi-threading will be key to improving your application performance.

Cheers,

Stu
 

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