multithreading - Is there a better way to block a C# timer when interacting with the user? -
I am using the System.Windows.Forms.Timer
component on the main form of an application Everybody checks for updates on the database, however, there are several possible interactions with the user, such as the modal dialog is being thrown for some tasks. In general, I do not want this timer if the user is "busy" or other database operation is active.
My current approach clearly shows the bracket "sensitive" checkDatabaseTimer.Stop () / start ()
pair (always try / end start
) Is used to ensure).
But it seems to me a nervousness: If any future code changes the code of this form, then it should be remembered to apply this stop / start bracket around any code, for example For this, the user is prompted for an input, so it seems easy to forget to do so.
Is there a better way to deal with this? Or is it just something we should be aware of because multithreading is like running with a scissor, is not one of those things that you can just argue is easy and safe?
Comments
Post a Comment