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.
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.
精彩评论