views:

45

answers:

2

I have a vb.net application which does some processing. This processing can take a while. The application doesn't respond until the processing has ended and then it handle all events (such as click on buttons) that the user has done during the processing. I'd like to add a "Stop" button so that the user can stop the processing at some point. How can I do that? Could threading the processing (which is done in a function of the application) be a possible solution?

I tried to add a button which change a boolean value and putting the code of the processing function inside a while statement based on that boolean value. However it doesn't work because the click event on the button is processed only after the end of the processing.

+2  A: 

Use a BackgroundWorker component to do your processing. This will allow your program to continue to respond to events while the processing continues to run. If you want to also provide a "Stop" button, the worker allows you to implement that as well.

Joel Coehoorn
Recommend using the new Tasks api if using VS2010
Chris Dunaway
A: 

can you explain more about using Tasks api or provide some links for more info?

Thanks.

jameslcs