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.

пре 2 година
пре 2 година
пре 2 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace HKHelper
  9. {
  10. public class Singleton<T> where T : new()
  11. {
  12. private static object _async = new object();
  13. private static T _instance;
  14. static readonly Lazy<T> instance = new();
  15. /// <summary>
  16. /// 获取实例
  17. /// </summary>
  18. /// <returns></returns>
  19. public static T GetInstance()
  20. {
  21. return instance.Value;
  22. }
  23. }
  24. public class HKHelper : Singleton<HKHelper>
  25. {
  26. /// <summary>
  27. /// 判断网络状况的方法,返回值true为连接,false为未连接
  28. /// </summary>
  29. /// <param name="conState"></param>
  30. /// <param name="reder"></param>
  31. /// <returns></returns>
  32. [DllImport("wininet")]
  33. public extern static bool InternetGetConnectedState(out int conState, int reder);
  34. /// <summary>
  35. /// 获取当前网络连接状态
  36. /// </summary>
  37. /// <returns>成功连接网络返回 true,未连接返回 false</returns>
  38. public bool GetNetworkState()
  39. {
  40. return InternetGetConnectedState(out int i, 0);
  41. }
  42. }
  43. }