Click here to Skip to main content
15,938,848 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:

I'm after some advise. I'm developing an application that runs on a windows 7 tablet with WiFi capabilities. I need to upload data when an internet connection is established.

I'm wondering if there is a method of firing a function call when an internet connection is established. The only idea I have had so far is a background thread which pings a web address at set intervals and when it makes a connection do my processing but this seems a little wasteful as it could be hours before an internet connection is established again.

I was wondering if anyone can direct me towards a more elegant solution?


I know there is a delegate for network connections like NetworkAvailabilityChanged. But I don't have any idea about a delegate for internet connection or an API. Because if it had existed, the Windows(OS) could have used it for itself. You know windows has a little delay to understand it has been disconnected from the internet.
The chief problem is the internet is based on Request and Response, then how could you check the internet avaiiability, without requesting and responsing from a remote server through the internet?!
Share this answer
merridus 12-Mar-12 17:29pm    
Thank you for this, I hadn't seen this function. I imagine I could combine this with pinging a web address to confirm an active internet connection when it has been confirmed that it's actually connected to a network.
Shahin Khorshidnia 12-Mar-12 17:33pm    
Yes, but I used it before and I had a little problem with multi network connections and I didn't follow it. It's about 2 years ago. I hope you can do it.

in addition to Shahins solution it seems there's a method to check internet connection when P/Invoking wininet.dll.

[DllImport("wininet.dll", SetLastError = true)]
static extern bool InternetCheckConnection(string lpszUrl, int dwFlags, int dwReserved);[^]

Easy to try, maybe it's working for you.

A second idea could be to check if user has started his browser. Something like if Process Firefox or ie is executed, or a process you pretty surly know that's executed on connection (maybe proof as a windows service), begin your uploading.

A third idea could be using a method that matches your requirements from the wifi wlanapi.dll.

Share this answer
merridus 13-Mar-12 4:49am    

Thank you, I'd discovered that function and I've used a NetworkAvailablilityChanged listener with it and it seems to accurately tell me when the machine is connected to a network and if the internet is available. This should set me on my way.
El_Codero 13-Mar-12 6:24am    
Good news that it works for you. Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900