I have 3 lists of the following type:
- folderName : String
- FTPcount : Int
- Expectedcount : Int
All are related to each other (based on their index in the list) and I want to pass them as argument to BackGroundWorker which reads the folderName while increments FTPcount and Expectedcount.
How can I pass them (by reference ? ) such that I will be able to see the increments after each one has finished its execution ?
List<string> folderName = new List<string>();
List<int> Expectedcount = new List<int>();
List<int> FTPcount = new List<int>();
foreach (string folder in Properties.Settings.Default.Folders)
{
BackgroundWorker bg = new BackgroundWorker();
bGs.Add(bg);
Expectedcount.Add(new int());
FTPcount.Add(new int());
folderName.Add(folder);
bg.DoWork += new DoWorkEventHandler(Process_Instiution);
bg.RunWorkerAsync(new { folderName = folder, Expected = Expectedcount[Expectedcount.Count - 1] as object, FTP = FTPcount[FTPcount.Count - 1] as object });
}
while (true)
{
bool IsBusy = false;
foreach (BackgroundWorker bg in bGs)
if (bg.IsBusy)
{
IsBusy = true;
break;
}
if (IsBusy)
Application.DoEvents();
else
break;
}
//Code to read the various List and see how many files were expected and how many were FTPed.
Use the DoWork(Object data) method that specifics the argument. You will have to cast and it retrieve it from args Argument Property.
I would either create a object wrapper to pass the data or use an anonymous type.