Hi,
In VS2022 I can create a windows form using C#
Lets say that there are 4 buttons on the form, button1, button2, button3, button4
Each button has an onclick method
Lets say that all it does when you click a button is show a message "Hello, Button 1 clicked " etc.
finally lets say that you start the windows application and you then click button1 and it displays the message, my question is:
Until you click another button, what is happening in the background, is there some process that is just waiting for a button click or is the application code doing something else, IE moving from 1 method to the next until it knows a button has been clicked.
What I'm ultimately after is knowing how to get the application to do something else whilst waiting for a button click but then if a button has been clicked then stop doing whats its doing and concentrate on the button click
or
am I talking crap lol
Sam HobbsPosted Feb 21, 2026, 3:29 PM
Operating systems are capable of multiprocessing and multitasking. The OS (Windows) switches tasks very often. Look at the Processes tab of the Task Manager, your computer is busy doing many things. When your application has nothing to do then the OS switches to something else. When there is nothing to do it waits. The percent of CPU value indicates how much time the processor is not waiting.
What you are looking for is BackgroundWorker. It is designed to allow a Windows Forms application to do stuff without affecting the User Interface. See the following.
How to: Implement a Form That Uses a Background Operation - Windows Forms | Microsoft Learn
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-implement-a-form-that-uses-a-background-operation
BackgroundWorker Component Overview - Windows Forms | Microsoft Learn
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/backgroundworker-component-overview