【发布时间】:2010-06-06 23:03:15
【问题描述】:
我想从两个单独的线程向 DataGridView 添加行。我用代表和 BeginInvoke 尝试了一些方法,但没有用。
这是我的行更新函数,它是从线程中的另一个函数调用的。
public delegate void GRIDLOGDelegate(string ulke, string url, string ip = "");
private void GRIDLOG(string ulke, string url, string ip = "")
{
if (this.InvokeRequired)
{
// Pass the same function to BeginInvoke,
// but the call would come on the correct
// thread and InvokeRequired will be false.
object[] myArray = new object[3];
myArray[0] = ulke;
myArray[1] = url;
myArray[2] = ip;
this.BeginInvoke(new GRIDLOGDelegate(GRIDLOG),
new object[] { myArray });
return;
}
//Yeni bir satır daha oluştur
string[] newRow = new string[] { ulke, url, ip };
dgLogGrid.Rows.Add(newRow);
}
【问题讨论】:
-
怎么不行?它编译吗?你有什么例外吗?
标签: c# datagridview multithreading