Hi Ricardo,
There are a few ways of doing it , it all depend of how/where you run the
random generator, I will show you two escenarios
1- gen. runs on the same thread.
while you are generating numbers , between number generation you call
Application.DoEvents() this process the events queries, you can then use a
Stop button that set a flag to false, before the next number is generated yo
check for this flag, like this:
bool generate = true;
void generaterandom( object sender, EventArgs e )
{
while ( generate)
{
// generate it and update the UI
Application.DoEvents();
}
}
void Stop_OnClick( object sender, EventArgs e )
{
generate = false;
}
2- run the generator on another thread and then the Stop button can pause
the thread execution, remember that if you use this approach you have to
make sure that the call to update the interface be called in the main thread
using Control.Invoke
Pd: I will not post code for this as its a little more complex, just drop
me a note if you need it
HTH,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Ricardo said:
I made a program that generate random numbers and put it in a listbox when
the user click go.
The problem is: how can i made a button stop, to stop the method that is
running???
[]s...