Happy New Year all,
I am developing a C# Winforms SDI application that relies heavily on background worker threads to carry out long-running database queries. My main dialog box contains a progress label and progress bar; but also a Toolstrip Menu, which contains two ToolStrip Labels and two Toolstrip Progress Bars. I update the progress labels and progress bars via delegates called by event handlers (OnUpdateProgress(object sender UpdateProgressEventArgs e)).
I am seeking your expert opinion on what approach I should use when invoking the UI delegate with regards to trying to achieve a more "generic" and reusable approach.
Thusfar I have considered 2:
(1) When instantiating a worker thread from the main dialog to carry out a background task, pass in a handle to the Label and Progress Bar controls to be updated when the event handler calls back, and (2) Pass in the name of the Label and Progress Bar to be updated when the event handler is invoked; and use the Form.Find method to retrieve a Control[] of matching controls.
I cannot decide on which of these approaches to use; or indeed if there is a better way of doing this. I believe that method (1) is a little clunky and inelegant; but that method (2) is prone to failure and notwithstanding that the Form.Find method may introduce unreasonable overhead searching for embedded Toolstrip Menu Controls.
I have searched previously asked/answered questions for a solution.
Your advice if much appreciated!