I've got a winforms application that is set up in the following manner: 2 buttons, a textbox, an class object MX with a collection K as its member, function X and another function, Y.
- Function X parses a large database and enumerates some of its data in collection K.
- Button 1 calls function X.
- Function Y walks through the above collection and prints out the data in the textbox.
- Button 2 calls function Y.
I'd like to call function X through a worker thread in such a way that:
- The form remains responsive to user input. This comes intrinsically from the use of a separate thread.
- There is never more than a single instance of function X running at any point in time.
- MX/K can be accessed by both functions at all times.
What would be the most efficient implementation of the above environment ?