我想将一些数据从一个事件处理程序传递到另一个,但我有点困惑。
在下面的代码中,我有两个事件:
- 一个是“计时器已过去”事件
- 第二个是从“计时器已过去”事件引发的“Ping完成”事件
在“Ping完成”事件中,我需要访问来自计时器已过去事件的一个变量。我该怎么做?
void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
for (int i = 0; i < this.View.Rows.Count; i++)
{
this.IP = View.Rows[i].Cells[2].Value.ToString();
PingOptions Options = new PingOptions(10, true);
Ping thisPing = new Ping();
thisPing.SendAsync(IPAddress.Parse(IP), 100, new byte[0], Options);
thisPing.PingCompleted += new PingCompletedEventHandler(thisPing_PingCompleted);
}
}
void thisPing_PingCompleted(object sender, PingCompletedEventArgs e)
{
//i need to accsess the "int i" of the above loop Here
}
var resp = await thisPing.SendPingAsync(...)
。 - EZI