2

In Eclipse I saw an implementation of IProgressMonitor - which is subsequently in SharpDevelop too but I'm not sure how this works. Is there an example of this elsewhere that might be a bit easier to understand?

What I'm trying to achieve is a method of tracking the progress of a bunch of tasks (which vary greatly from 20mins to 5seconds) by the one progressbar (tasks can be added at any point in time).

Would something like this be a good alternative/idea?

interface ITask
{
    int TotalWork; // ProgressMax
    event Progresschanged; // Notifies of the current progress
    event ProgressComplete;
}

Then the "Monitor" simply uses the Observer pattern to monitor the two events. When all the progressbars have completed it will hide the progressbar. The other issue is that these are seperate threads that are being spawned.

Could anyone advise me on something or lead me on the right track?

3
  • IProgressMonitor is not part of .net framework. Looking through google, it seems to be part of the eclipse api... /shrug. Commented Mar 30, 2009 at 12:15
  • I updated the example that I gave, sorry I didnt see you post until just now: <a href="stackoverflow.com/questions/596991/c-multi-thread-pattern/…> Commented Jun 25, 2009 at 15:37
  • (tasks can be added at any point in time) - so it's ok if your progress bar shrinks? Commented Jun 25, 2009 at 15:54

2 Answers 2

2

Maintain a list of tasks and weight them by their overall contribution;

struct Task { int work, progress  }
class OverallProgress
{
    List<Task> tasks;
    int Work { get { return tasks.Sum(t=>t.work; } }
    int Progress { get { return tasks.Sum(t=>t.progress/t.work); } }
    void AddTask(Task t) { tasks.Add(t); }
}

This implementation is only meant to illustrate the concept.

Yes this implementation is not efficient. You can store the computed Work so that you recalculate it only when a new task is added.

Yes you may lose precision by doing integer division. You'll have to wire up your own events, too.

If you have trouble with these tasks, please mention that and I or someone else can provide a full implementation of such a class.

Sign up to request clarification or add additional context in comments.

Comments

1

System.Component.BackgroundWorker handles progress notification. I would spawn multiple BG workers and have them report back to a single method on the UI thread. You can then update your progress bar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.