I've struggled for the last couple of months to come up with some clean code to report progress to a user. Everything always seems to boil down to:
ReportProgress("Starting Task 1");
doTask1();
ReportProgress("Task 1 is done");
ReportProgress("Starting Task 2");
doTask2();
ReportProgress("Task 2 is done");
//etc... where report progress does some form of output to the user.
The good coder in me screams "There's got to be a cleaner way!" But I'm stumped. Any thoughts?
EDIT :: I'm looking more for information on architectural information as opposed to implementation specific. The code given is very oversimplified.
You could call ReportProgress from inside the doTask methods, that might make it look a little cleaner, instead you would just have:
The reporting would be handled inside those methods.
You could use AOP, but my brain screams KISS!!(Keep It Simple Stupid) in this case. If this is just a simple representation of something more complicated that you are dealing with, AOP could be an option.