How do I reference a backgroundworker on a user control that is on a tabpage?
I have a GUI that allows a user to add tabpages to a tab control. Everytime the user adds a tab, a user control is placed on the new tab. The user control has a background worker on 开发者_开发技巧it, as well as several other controls. My question is this: Can I access the backgroundworker specific to a tabpage? In other words, can I tell the program to use the backgroundworker found on tab index 0 to run a process, and then tell the backgroundworker on tab index 1 to run a different process?
Maybe you can have a list of BackgroundWorkers and everytime you add a tab you create a new worker something like this in c#
public class Foo : Form{
List<BackgroundWorkers> bgs;
......
void AddNewTab(DoWorkEventHandler bw_DoWork, RunWorkerCompletedEventHandler bw_RunWorkerCompleted, ProgressChangedEventHandler bw_ProgressChanged)
{
//bgs was initialized in the ctr
var bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true; ;
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bgs.Add(bw)
}
.....
void ExecuteBackgroundWorker(int tabindex)
{
bgs[tabindex].RunWorkerAsync();
}
void ExecuteBackgroundWorkerTask(int tabindex, DoWorkEventHandler bw_DoWork)
{
bgs[tabindex] += new DoWorkEventHandler(bw_DoWork);
bgs[tabindex].RunWorkerAsync();
}
}
Something like that.....but translated to vb.net....
精彩评论