473,767 Members | 7,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NetworkAvailabi lity 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.Netw orkAvailability Changed.
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 NetworkAddressC hanged, 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 InitializeCompo nent(). (Note: It
doesn't work if I move it to the load event either.)

updateNetworkSt atus(NetworkInt erface.GetIsNet workAvailable() );
NetworkChange.N etworkAvailabil ityChanged +=
new
NetworkAvailabi lityChangedEven tHandler(myNetw orkAvailability ChangedHandler) ;

And here's my event handler:

private void myNetworkAvaila bilityChangedHa ndler(object sender,
NetworkAvailabi lityEventArgs args)
{
updateNetworkSt atus(args.IsAva ilable);
}

And here's the last method:

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

this.Invoke(new WaitCallback(up dateNetworkStat us), args.IsAvailabl e);

instead of just calling updateNetworkSt atus.

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 1371

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

Similar topics

6
5333
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
3896
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 response.write on its click handler but it won't fire either telling me no button click events will fire. But my calendar control on the same page does fire. In the debugger I put a break point in the calendar event and the button
3
3157
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. I get the postback but I never have the event called. It works fine in i.e.
2
8358
by: Breeto | last post by:
Can anyone please tell me why the following doesn't work... using System; using System.Web; namespace AspTests {
0
1856
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 child form implements an event handler for the Resize event. Inside BaseApplicationForm.InitializeComponent, this.ClientSize is set to a value. On most of our developers' machines, this.ClientSize = ....; does NOT fire the Resize event, which makes...
9
2471
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 post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
19
4757
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 DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
5
3268
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 to it, and it doesn't work. I think I understand why, however, I would like to know if there is anything that I can bind to my variable that will fire the specified function whenever the value changes.
0
268
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. 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
0
9575
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9960
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8840
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.