views:

181

answers:

1

Hi,

I want to add an progress bar into my C# based application. I would like to know what is the good way of updating its value at particular events? My problem is, I have single function in UI which does all the processing.This function in turn calls many more functions, creates objects, updates database, etc. (basically performs all the work) and returns values in an output file. I have access to that function only. So in this how to update the progressbar's value at the end of each step?

What is the best practice for this kind of situation? What is the good way to keep UI logic and business logic seperate? I want to avoid writting progressbar related code in my library code.


Please suggest some solution. Thanks and Regards,

+3  A: 

If you have a class that's your "worker class" - the class that you call your single function through - then you can create a Progress property on that class. Then, as the operation proceeds, update the value of that property and throw an event to indicate that it's changed.

You could either define a specific ProgressChanged event or, if you're using data binding, use the INotifyPropertyChanged interface.

Then in your UI: either use databinding, or specifically listen for that event and update the progress bar accordingly.

Dan Puzey
Thanks a lot for such a detailed answer. I think idea of using event will work. Thanks again !!!
Shekhar