我有一個列表。我把我所有的查詢輸出。現在使用 線程做一些處理。所以當工作完成後,需要更新列表項值。 請參閱我下面的代碼:如何更新列表的項目值?
公開宣稱列表:
public static List<string[]> OutboxList = new List<string[]>();
從數據庫中讀取數據和操作的列表:
OutboxQueryCommand.CommandText = "SELECT top 5 id, status from TableA";
SqlDataReader OutboxQueryReader = OutboxQueryCommand.ExecuteReader();
while (OutboxQueryReader.Read())
{
string[] OutBoxFields = new string[7];
OutBoxFields[0] = OutboxQueryReader["id"].ToString();
OutBoxFields[1] = OutboxQueryReader["status"].ToString();
OutboxList.Add(OutBoxFields);
}
foreach (string[] OutBoxFields in OutboxList)
{
id = OutBoxFields[0];
status = OutBoxFields[1];
Thread OutboxThread = new Thread(() => OutboxThreadProcessor(id,status));
OutboxThread.Start();
}
打電話線程的方法:
static void OutboxThreadProcessor(string id,string status)
{
//predefine value of status is "QUE". Process some work here for that perticular item list.if data process success full then need to update
// the status of the list item
// need to update the perticular value of that list item here.
How i do it???????
//Say for Example 1-> Success
// 2-> Failed
// 3-> Success
}
靜態列表通過線程顯示error..can你請幫忙嗎?線程OutboxThread =新線程((()=> OutboxThreadProcessor(OutboxList)); – riad
您正在傳遞列表變量'OutboxList'。看看我的答案,你應該通過'OutBoxFields' –
我已經嘗試了OutboxFileds。但都顯示錯誤..線程OutboxThread =新的線程((()=> OutboxThreadProcessor(OutBoxFields));有沒有限制列表.. ?? – riad