473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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
not.

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 +=
new
NetworkAvailabilityChangedEventHandler(myNetworkAv ailabilityChangedHandler);

And here's my event handler:

private void myNetworkAvailabilityChangedHandler(object sender,
NetworkAvailabilityEventArgs args)
{
updateNetworkStatus(args.IsAvailable);
}

And here's the last method:

private void updateNetworkStatus(object state)
{
//do stuff
System.Diagnostics.Debug.Print("***Network status changed to {0}.***",
state.ToString());
}
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.

Thanks,
RobinS.
GoldMail.com

Apr 11 '08 #1
0 1333

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
2
by: Sam Miller | last post by:
Hi, I have a button event that won't fire. I left it on Friday and it worked fine. I came back in on Monday and it won't fire. I tried putting another button and just putting a...
3
by: jeff29_b | last post by:
I am having a strange problem on a web form. I have an image button with an OnClick event handler. When I click the image the event isn't being called in the code behind when browsing in firefox....
2
by: Breeto | last post by:
Can anyone please tell me why the following doesn't work... using System; using System.Web; namespace AspTests {
0
by: Patrick Lioi | last post by:
We have form that is used as the base class of all of our forms, let's call it BaseApplicationForm. We have another form, say ChildApplicationForm that inherits from BaseApplicationForm. The...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
5
by: Daz | last post by:
Hi everyone. Another simple question which should hopefully warrent a simple answer. I would like a function to be run whenever a variable is updated. I have tried binding the onchange event...
0
by: RobinS | last post by:
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.