2012-11-15 60 views
0

我有以下類型的3名名單:傳遞參數的BackgroundWorker

  1. FOLDERNAME:字符串
  2. FTPcount:詮釋
  3. Expectedcount:詮釋

所有都彼此相關(基於它們在列表中的索引),我想將它們作爲參數傳遞給BackGroundWorker,它讀取folderName,同時增加FTPcount和Expectedcount。

我該如何傳遞它們(通過引用?),以便在每個執行完成後我能夠看到增量?

 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. 
+0

事實上,你有一個'Application.DoEvents()'調用意味着你的方法有缺陷。 :(可能需要做一些改進 –

+0

我知道這一點,我正在研究它(你能爲此提出一些建議嗎?)現在我需要關於傳遞參數的幫助。 –

回答