C# 将参数传递给BackGroundWorker

C# 将参数传递给BackGroundWorker,c#,backgroundworker,C#,Backgroundworker,我有以下类型的3个列表: folderName:String FTPcount:Int 预期计数:Int 所有这些都是相互关联的(基于它们在列表中的索引),我想将它们作为参数传递给BackGroundWorker,后者在递增FTPcount和Expectedcount的同时读取folderName 如何传递它们(通过引用?),以便在每个增量完成执行后,我能够看到增量 List<string> folderName = new List<string>();

我有以下类型的3个列表:

  • folderName:String
  • FTPcount:Int
  • 预期计数:Int
  • 所有这些都是相互关联的(基于它们在列表中的索引),我想将它们作为参数传递给
    BackGroundWorker
    ,后者在递增FTPcount和Expectedcount的同时读取folderName

    如何传递它们(通过引用?),以便在每个增量完成执行后,我能够看到增量

            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.
    
    List folderName=new List();
    List Expectedcount=新列表();
    List FTPcount=新列表();
    foreach(Properties.Settings.Default.Folders中的字符串文件夹)
    {
    BackgroundWorker bg=新的BackgroundWorker();
    添加(bg);
    Expectedcount.Add(new int());
    FTPcount.Add(newint());
    添加(文件夹);
    bg.DoWork+=新DoWorkEventHandler(流程机构);
    RunWorkerAsync(新的{folderName=folder,Expected=Expectedcount[Expectedcount.Count-1]作为对象,FTP=FTPcount[FTPcount.Count-1]作为对象});
    }
    while(true)
    {
    bool IsBusy=false;
    foreach(后台工作人员bg在bGs中)
    如果(bg.IsBusy)
    {
    IsBusy=true;
    打破
    }
    如果(忙)
    Application.DoEvents();
    其他的
    打破
    }
    //代码读取各种列表,查看预期的文件数和FTPed文件数。
    
    使用指定参数的。你必须施放它,然后它从中取回它


    我可以创建一个对象包装器来传递数据,也可以使用匿名类型。

    事实上,您有一个
    应用程序.DoEvents()
    调用,这意味着您的方法有缺陷(可能需要做一些修改。我知道这一点,我正在努力(你能提出一些建议吗?)。