dseaver
IS-IT--Management
- Jul 13, 2006
- 467
I have a dll which I wrote that contains a function that could take a minute or so (reading a lot of files and doing various other things). In that function I use a foreach loop. I call this function from my Gui exe in a background worker. How do I raise an event in my function that will be seen as a progress changed event to the background worker?
Code:
//doesSomething.dll
public void reallyLongFunction()
{
foreach(item thing in listOfItems)
{
//Want to report the start of this iteration
//does a whole set of functions for each item
:
:
}
}
Code:
//Gui.exe
void CallBgFunction()
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerAsync();
worker.WorkerReportsProgress = true;
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
doesSomething.Class item = new doesSomething.Class();
item.reallyLongFunction();
}