我有一个列表。我把我所有的查询输出。现在使用 线程做一些处理。所以当工作完成后,需要更新列表项值。 请参阅我下面的代码:如何更新列表的项目值?
公开宣称列表:
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