问题
I'm programming a Windows local service using C++ and WinAPIs. From within that service I need to know that an Internet connection is available (in general) so I came up with the InternetGetConnectedState API but then after reading the MSDN I found this in the Remarks section:
In addition, it should not be used from a service.
Well, "thank you", Microsoft!
Does anyone have any idea why and what alternative can I use from a service.
PS. I don't want to use the ping approach because obviously there's no way of knowing that the site I'm pinging is up, so it then opens up a whole new can of worms.
回答1:
Generally you don't need to care whether the Internet is available, you just attempt to make the connection to the site and deal with any failure.
来源:https://stackoverflow.com/questions/11320366/internetgetconnectedstate-and-it-should-not-be-used-from-a-service-statement-f