|
-
July 5th, 2012, 07:46 PM
#1
Trying to establish if Internet connection is available from a service
I work on the code that has a worker thread in a local service application that needs to send a lengthy submission to a web server via an HTTP connection. Such submission is scheduled once so often (say, once every 24 hours.) So the current algorithm simply tries to do the transmission to the web server and then re-schedules for the next time. The problem is that at times the Internet connection might not be available on a client computer. So my idea was to check if Internet is available and if it is to continue on with the submission and if it is not, then to reschedule in a little while (in 30 seconds, for instance) to retry again.
So I did some search and found the InternetGetConnectedState() API that should do just that. Very simple, right? Well, wrong ... I kept reading the MSDN documentation and found this little sentence:
 Originally Posted by MSDN
In addition, it should not be used from a service.
I was able to find out that this warning is there due to the fact that evidently that API can display a user diaglog (for no apparent, or at least documented, reason.)
So my question is, since I can't use that API, what shall I use instead?
PS. To prevent answers, such as, "continue on submitting your data and handle errors" -- First off, there's "a million" socket errors that may result from inability to connect vs. server's inability to respond. So I need to clearly know, is it the client computer that simply doesn't have an Internet connection at the moment, or if it's a server issue. And in the latter case I will not make this service push on another submission in 30 seconds and swamp the server even more.
Secondly, the process of submission takes a lot of client computer resources to generate and submit, so it'd be very nice to know right before I start this "costly" process, whether the most basic prerequisite is actually available -- i.e. Internet connection -- before I begin it.
So hopefully someone knows a better way of finding out if an Internet connection is available from a local service...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|