Reputation: 1620
I have created a class library in my project which scans a series of files. In my main project which uses this DLL as a reference, I'd like to create a progress bar which shows how many file have been scanned so far.
The dll class makes use of a foreach loop since it's purpose is to turn each file into a hash code. The foreach loop has been used to join each converted segment of a file together so that I can have a 512 bit long code, and then it proceeds to the next file.
I have defined a variable in the dll class which is -->
public static int value_ = 0;
This variable is updated at the the end of the foreach loop.
Now in my main project, I'd like to use this variable to update my progress bar at the same time the function in my class library project is running.
For example :
DLL.function();
pb.value = value_;
I'd appreciate any hint on how I can implement this.
Upvotes: 0
Views: 1941
Reputation: 12748
Your main program will have to call your function using a thread, the Background Worker can help you with this.
To update the progress bar you'll have to look at events and delegate. Everytime you process an item, you could raise an event. Then your main program could handle this event and update the progress bar.
Upvotes: 0
Reputation: 13877
You can use a Background Worker to do work and report progress.
worker.WorkerReportsProgress = true;
And now you can have this progress report be triggered by an event you subscribe to.
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
In doing so, you can create a progress bar than can update itself based on this worker_ProgressChanged
event, triggered by your method.
Upvotes: 3