I am using a backgroundworker that can have n instances. Problem is the DoWork method (that has the 'sender' parameter which is the BackgroundWorker) calls other code that produces a callback - thus i dont have the sender.
How can i determine the BackgroundWorker that the current code is running under?
ex:
private void SetupThread()
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(DoTheWork);
}
private void DoTheWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
// I know that sender here can be converted, but thats no good for me
MyClass.DoSomething(); // This will produce a callback(event) from MyClass
}
private void MethodCalledFromEventCallback()
{
// Here is where the actual work is being done. I need to determine which
// instance of the Backgroundworker is calling it so that i can use the
// UpdateProgress method
// I cannot do this :-( (BackgroundWorker)System.Threading.Thread.CurrentThread;
}
Im probably just overlooking something (unless threadpool is in order :-( )
Im sure this is easily doable with the BackgroundWorker ... any ideas?
edit
I caused some confusion in my description, here are some more facts :-) 1.) I already call the bw.RunWorkerAsync() 2.) The class that invokes the event MethodCalledFromEventCallback has no knowledge of the background thread 3.) I cannot (due to design requirements) include the Backgroundworker as a parameter
Thanks :-)