【发布时间】:2012-04-02 15:27:37
【问题描述】:
我有一个应用程序 ping datagridview 中的每个 IP,以编译响应 IP RoundtripTime 列表。完成该步骤后,我会将 RoundtripTime 推回 datagridview。
...
foreach (DataGridViewRow row in this.gvServersList.Rows)
{
this.current_row = row;
string ip = row.Cells["ipaddr_hide"].Value.ToString();
ping = new Ping();
ping.PingCompleted += new PingCompletedEventHandler(ping_PingCompleted);
ping.SendAsync(ip, 1000);
System.Threading.Thread.Sleep(5);
}
...
private static void ping_PingCompleted(object sender, PingCompletedEventArgs e)
{
var reply = e.Reply;
DataGridViewRow row = this.current_row; //notice here
DataGridViewCell speed_cell = row.Cells["speed"];
speed_cell.Value = reply.RoundtripTime;
}
当我想使用DataGridViewRow row = this.current_row; 获取当前行但我得到一个错误关键字'this' is not available in static function.so,如何将值推回datagridview?
谢谢。
【问题讨论】:
标签: c# .net multithreading network-programming backgroundworker