C# software freezing when setting property to true

Windows forms have a UI thread. This thread is responsible for updating the UI, and handling UI related events. If this thread ever becomes blocked then your UI will become unresponsive.

The timer tick event is handled by this UI thread, so when you start a long loop inside this event handler the UI thread is unable to process the rest of the UI and your program appears to freeze.

There are several ways to fix this in your code. You might remove the

while(runBot == true)

from your timer tick event, and let the timer tick periodically. You could disable the timer when you don’t want the processrunning check to run.
You could disable buttons if there’s something you don’t want the user to click during this time.

Another option would be to have a background thread that calls processrunning and sets a flag accordingly.

Browse More Popular Posts

Leave a Comment