Hi all -
I need some advice on how to handle multithreading in a GUI. I wrote an application in C# using only the GUI thread (see screenshot) and at times there are "long operations" where the database is being accessed and the right hand pane is being filled with the record data. For example if they click on a tree node, it might take a while for the right hand pane to load, because of database access required and many records. Also they might add many records at once using the Add feature of the right hand pane. I am trying to implement BackgroundWorkers for these operations, but I don't know what to do now, to handle/prevent user clicks during the BW operations. During the long operation the user has the opportunity to click a different node in the tree, or click a menu item, etc. that would cause the long operation to cease midstream.
These are the choices I see right now:
- Make them wait for the operation to complete by setting Form.Enabled to false. But then everything grays out and looks crappy.
- Show a progress dialog modally so they can't click on the form underneath. But that stops execution of the GUI thread so that's no good.
- (Most difficult but probably correct!) Handle the BW cancel feature such that if they click a different tree node or a menu item, the long operation gracefully cancels and they are able to move to the new node/new right hand pane.
I would be interested in "making them wait" (i.e. prevent all clicks until the long operation is complete) but I do not see a way to do this without graying out and looking crappy. Besides I want my app to be professional - i.e. live up to what any user expects to see from a Windows application.
Any help/general tips would be appreciated.