471,348 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

NetworkAvailability event won't fire or handler isn't seeing it

My application needs to know when the network availability has changed and
do some stuff when it does.

I wrote a small WinForms app to test System.Net.NetworkAvailabilityChanged.
It works great.

I put the same logic in my main application, and the event is never caught
by my handler.

If I put in NetworkAddressChanged, it *is* fired and caught. But I don't
need to know if the address changed, I need to know if the user is online or

Here's my code:

In the constructor of my main form after InitializeComponent(). (Note: It
doesn't work if I move it to the load event either.)

updateNetworkStatus(NetworkInterface.GetIsNetworkA vailable());
NetworkChange.NetworkAvailabilityChanged +=
NetworkAvailabilityChangedEventHandler(myNetworkAv ailabilityChangedHandler);

And here's my event handler:

private void myNetworkAvailabilityChangedHandler(object sender,
NetworkAvailabilityEventArgs args)

And here's the last method:

private void updateNetworkStatus(object state)
//do stuff
System.Diagnostics.Debug.Print("***Network status changed to {0}.***",
One blog I found recommended this in the event handler:

this.Invoke(new WaitCallback(updateNetworkStatus), args.IsAvailable);

instead of just calling updateNetworkStatus.

That doesn't work either, and I'm not sure why I would use that over just
calling it.

Any help or advice would be greatly appreciated.


Apr 11 '08 #1
0 1205

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sam Miller | last post: by
3 posts views Thread by jeff29_b | last post: by
reply views Thread by Patrick Lioi | last post: by
9 posts views Thread by jeff | last post: by
19 posts views Thread by Daniela Roman | last post: by
5 posts views Thread by Daz | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.