0

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

  1. 文件夹名称:字符串
  2. FTP计数:整数
  3. 预期计数:整数

所有都相互关联(基于它们在列表中的索引),我想将它们作为参数传递给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.
4

1 回答 1

0

使用指定参数的DoWork(Object data) 方法您将不得不强制转换并从args Argument Property中检索它。

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

于 2012-11-15T02:39:29.127 回答