The Network and the Connection classes both raise a StateChanged event when their state changes. Create a handler for this event that accepts an instance of the StateChangedEventArgs class, which exposes the IsConnected property
public void StateChangeHandler(object sender, StateChangedEventArgs e)
{
if (e.IsConnected)
{
MessageBox.Show("Now connected");
}
else
{
MessageBox.Show("Now disconnected");
}
}
Connect your event handler to the StateChanged event of the Connection or Network you want to monitor.
conn.StateChanged += StateChangeHandler;The Connection class exposes a method named UpdateStatus that you can call to raise the StateChanged event and obtain information through your event handler on the connectivity status.
netwk.StateChanged += StateChangeHandler;
conn.UpdateStatus();
No comments:
Post a Comment