|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace HKHelper
- {
-
- public class Singleton<T> where T : new()
- {
- private static object _async = new object();
-
- private static T _instance;
-
- static readonly Lazy<T> instance = new();
- /// <summary>
- /// 获取实例
- /// </summary>
- /// <returns></returns>
- public static T GetInstance()
- {
- return instance.Value;
- }
- }
-
-
- public class HKHelper : Singleton<HKHelper>
- {
- /// <summary>
- /// 判断网络状况的方法,返回值true为连接,false为未连接
- /// </summary>
- /// <param name="conState"></param>
- /// <param name="reder"></param>
- /// <returns></returns>
- [DllImport("wininet")]
- public extern static bool InternetGetConnectedState(out int conState, int reder);
- /// <summary>
- /// 获取当前网络连接状态
- /// </summary>
- /// <returns>成功连接网络返回 true,未连接返回 false</returns>
- public bool GetNetworkState()
- {
- return InternetGetConnectedState(out int i, 0);
- }
-
- }
- }
|