Events and delegates, how do I code it 2 levels deep?
Class1 creates and calls a method in Class2. Class2's method 开发者_C百科updates it progress to an event handler in Class1. But now Class2's method needs to call a method in class3. How can class3 update it's method's progress to class1? Do I need to daisy chain the events and delegates all the way down each level?
(I'm using the MVC pattern, The UI class calls the controller class which calls a worker class. I need 2 progress bars updated in the UI class. A main progress bar updated as controller methods finish and a sub progress bar that upgrades as a loop processes in the worker class. The controller runs in a background process so the UI doesn't hang.)
The worker class reports to the controller which then notifies the UI of the progress. The worker class and UI shouldn't and won't know each other. Just create another event pair between worker class and controller (this is called event bubbling or event chaining, thanks @Abel).
精彩评论