I am trying to pass some data from one event handler to another, but i am a little bit stuck. In the following code, I have two events:
- one is the "timer elapsed" event
- the second is the "Ping Completed" event which is raised from the "timer elapsed" event
In the "Ping Completed" event, I need to access one variable from the timer elapsed event. How can I do that ?
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
}