public void Close()
        {
            if (_IsClosing)
            {
                return;
            }
            _IsClosing = true;

            try
            {
                _UsbDeviceConnection?.Dispose();
                _UsbDevice?.Dispose();
                ReadUsbInterface?.Dispose();
                WriteUsbInterface?.Dispose();

                _UsbDeviceConnection = null;
                _UsbDevice           = null;
                ReadUsbInterface     = null;
                WriteUsbInterface    = null;
            }
            catch (Exception)
            {
                //TODO: Logging
            }

            _IsClosing = false;
        }
Esempio n. 2
0
        public sealed override void Dispose()
        {
            if (disposed)
            {
                Logger.LogWarning(Messages.WarningMessageAlreadyDisposed, DeviceNumberId);
                return;
            }

            disposed = true;

            Logger.LogInformation(Messages.InformationMessageDisposingDevice, DeviceNumberId);

            Close();

            try
            {
                _UsbDeviceConnection?.Dispose();
                _UsbDevice?.Dispose();
                ReadUsbInterface?.Dispose();
                WriteUsbInterface?.Dispose();

                _UsbDeviceConnection = null;
                _UsbDevice           = null;
                ReadUsbInterface     = null;
                WriteUsbInterface    = null;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Dispose error DeviceId: {deviceNumberId}", DeviceNumberId);
            }

            _InitializingSemaphoreSlim.Dispose();

            base.Dispose();

            GC.SuppressFinalize(this);
        }