You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.5 KiB

  1. //using GVL;
  2. using Microsoft.Win32;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace HBLConsole.Service
  11. {
  12. /// <summary>
  13. /// 其它通用库
  14. /// </summary>
  15. public class UniversalHelper
  16. {
  17. private volatile static UniversalHelper _Instance;
  18. public static UniversalHelper GetInstance => _Instance ?? (_Instance = new UniversalHelper());
  19. private UniversalHelper() { }
  20. [DllImport("wininet")]
  21. //判断网络状况的方法,返回值true为连接,false为未连接
  22. public extern static bool InternetGetConnectedState(out int conState, int reder);
  23. /// <summary>
  24. /// 获取当前网络连接状态
  25. /// </summary>
  26. /// <returns>成功连接网络返回 true,未连接返回 false</returns>
  27. public bool GetNetworkState()
  28. {
  29. return InternetGetConnectedState(out int i, 0);
  30. }
  31. public void Init()
  32. {
  33. //while (!GVL_VAR.GetInstance.NetworkConnectState)
  34. //{
  35. // //GVL_VAR.GetInstance.NetworkConnectState = GetNetworkState();
  36. // Thread.Sleep(1000);
  37. //}
  38. //ThreadManagerment.GetInstance.StartLong(new Action(() =>
  39. //{
  40. // //GVL_VAR.GetInstance.NetworkConnectState = GetNetworkState();
  41. // Thread.Sleep(1000);
  42. //}), "网络监听状态");
  43. }
  44. }
  45. }