Beispiel #1
0
        /// <summary>
        /// 启动服务
        /// </summary>
        public bool Start()
        {
            if (_serviceState)
            {
                return(true);
            }
            int rt = USBMonitorCoreDll.Initialize(Encoding.Unicode.GetBytes(UsbExePath));

            if (rt != 0)
            {
                LoggerManagerSingle.Instance.Error($"初始化USB监听服务失败! 错误码:{rt}");
                return(false);
            }

            _callback = new DelegateUsbDeviceStateChange(OnDeviceStateChanged); //将委托定义为全局,防止垃圾回收
            rt        = USBMonitorCoreDll.Start(_callback);
            if (rt != 0)
            {
                LoggerManagerSingle.Instance.Error($"启动USB监听服务失败! 错误码:{rt}");
                return(false);
            }
            _serviceState = true;
            return(true);
        }
 public extern static int Start(DelegateUsbDeviceStateChange callback);