I am working on a WinForms application and I have a user control. Buttons in a user control raise events to a form processed by another code. One of the buttons starts some processes that will cause problems if they run simultaneously. I have logic in the code for state management, so usually the user cannot start this process if it is already running. However, if the user double-clicks the button, he will start the process twice so quickly that it is difficult for me to prevent it.
I am wondering what is the best way to handle this?
I started by turning off the button in the click event, but the second click appears before the first click, which causes the button to turn off. Setting other flags in the code also did not catch it.
I am considering adding some kind of synchronization lock to the code that triggers the event, but I am wondering if you have any better idea.
Since this project is mostly finished, I am looking for answers that are not related to a radical rewrite of the application (for example, implementing a composite block of applications), however, do not hesitate to publish these ideas, as I can use them in my next projects.
source share