- public void Initial()
- {
- try
- {
- if (IsNetworkConnected)
- {
- SvMaster.Log.WriteInfo("网络连接成功");
- }
- else
- {
- SvMaster.Log.WriteError("网络连接失败,请检查网络!");
- }
- }
- catch (Exception ex)
- {
- SvMaster.Log.WriteError(ex);
- }
- }
- [DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
- public extern static bool InternetGetConnectedState(out int conState, int reader);
-
- public static bool IsNetworkConnected
- {
- get
- {
- return InternetGetConnectedState(out int n, 0);
- }
- }
说明:该方法亲测可用,记录。