My Pause button doesn't work

Please excuse me if I'm missing something really stupid, but this is my first widows forms application in a long time.

I have a form with several controls for setting params and three buttons (BEGIN, PAUSE, and RESUME) to control the action. the BEGIN button uses the params to do some lengthy processing with thousands of records. I want the PAUSE button to allow the user to pause the action until the user presses the RESUME button.

The problem is that once the processing starts the form no longer responds the clicking on the buttons? I do similar things in other programming environments, but this one has me stumped...

Thanks, Lippert
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi lippert;

The Microsoft Windows Form environment works as a single thread of operations. When the application starts it start something called the message pump. This message pump holds all the events that needs attention such as Button click events Textbox Text events and many other such type events. As each event is taken off the message pump the code in that event gets executed and when that event completes its task it gets the next event and processes it until there is no more events to be processed and just sits there just waiting for the next event to happen. So when you click the Begin button that code gets executed and no other events can get processed until it has completed. The result of this is that your form becomes unresponsive to the user. If you want to be able to interrupt the process then you will need to introduce another thread to handle the processing of the code that you placed in that button click event by moving it from the button click event handler to the new thread.  A couple of  examples of this can be seen in the, BackgroundWorker Class, At the bottom of the page you will see an example.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lippertDeveloperAuthor Commented:
Perfect answer, coherent and complete.... Thanks.
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.  ;=)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.