我在讀取字符串列表時遇到問題,下面是我的代碼。無法讀取列表中寫入的元素作爲BackgroundWorker
public partial class form : Form
{
public static List<String> errores = new List<String>();
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e){
BackgroundWorker bw = sender as BackgroundWorker;
// Extract the argument.
string arg = (string)e.Argument;
// Start the time-consuming operation.
// e.Result =
if (tags.prog2(arg) == false)
{
//guardar en lista de no completadas
form.errores.Add("a");
}
//some code here
}
private void buscar()
{
//Some code here
foreach (string i in rutas)
{
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
backgroundWorker1.WorkerSupportsCancellation = true;
backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
backgroundWorker1.RunWorkerAsync(i);
}
foreach (string prime in form.errores)
{
MessageBox.Show(prime);
}
}
}
但在列表中沒有元素,爲什麼會發生這種情況?
很顯然,我叫兩個功能
Aclaration FUNCTION1其BackgroundWorker的,所以它叫過很多次,我不知道這是關係到錯誤。
你叫'功能1()'第一? –
是的,我打電話給他們。 –
提供您用於調用這兩個函數的代碼。 – oxilumin