protected virtual void Dispose(bool disposing)
        {
            try
            {
                if (!_disposed)
                {
                    if (disposing)
                    {
                        //Cleanup managed objects
                        if (!_stopped)
                        {
                            this.StopListeners();
                        }

                        cardMonitor.Dispose();
                        cardMonitor = null;

                        cardFactory.Release();
                        cardFactory.Dispose();
                        cardFactory = null;
                    }
                    // Cleanup unmanaged objects
                }
                _disposed = true;
            }
            catch
            {
                throw new Exception("Unable to dispose smartcard manager");
            }
        }
示例#2
0
        /// <summary>Disposes the object.</summary>
        /// <param name="disposing">Ignored. It will call <see cref="Cancel()" /> in order to stop the background thread. The application context will be disposed if the user configured the monitor to do so at construction time.</param>
        protected virtual void Dispose(bool disposing)
        {
            Cancel();

            if (disposing && _releaseContextOnDispose && _context != null)
            {
                _context.Dispose();
            }
        }
示例#3
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_disconnectReaderOnDispose && _reader != null && _reader.IsConnected)
                {
                    _reader.Dispose();
                }

                if (_releaseContextOnDispose && _context != null && _context.IsValid())
                {
                    _context.Dispose();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Actual disposing code, ensures the class is only disposed of once.
        /// </summary>
        /// <param name="disposing">Whether we are also disposing of related objects</param>
        private void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing && Context != null)
            {
                Context.Dispose();
            }
            if (disposing && Reader != null)
            {
                Reader.Dispose();
            }

            disposed = true;
        }
示例#5
0
        /// <summary>Disposes the object.</summary>
        /// <param name="disposing">Ignored. It will call <see cref="Cancel()" /> in order to stop the background thread. The application context will be disposed if the user configured the monitor to do so at construction time.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (_is_disposed)
            {
                return;
            }

            if (disposing)
            {
                Cancel();
            }

            if (disposing && _releaseContextOnDispose && _context != null)
            {
                _context.Dispose();
            }

            _is_disposed = true;
        }
示例#6
0
 public void Dispose()
 {
     reader?.Dispose();
     context?.Dispose();
 }
示例#7
0
 public void Dispose()
 {
     _isoReader.Dispose();
     _context.Dispose();
 }
示例#8
0
        private void StartMonitor()
        {
            try {
                lock (_gate) {
                    _ctx = _contextFactory.Establish(_scope);
                }

                var readers = GetReaders(_ctx);
                OnInitialized(new DeviceChangeEventArgs(
                                  readers,
                                  Enumerable.Empty <string>(),
                                  Enumerable.Empty <string>()));

                var noServiceCount = 0;
                while (true)
                {
                    try {
                        var newReaderList = GetReaders(_ctx);
                        var attached      = GetAttachedReaders(readers, newReaderList).ToList();
                        var detached      = GetDetachedReaders(readers, newReaderList).ToList();

                        if (attached.Any() || detached.Any())
                        {
                            OnStatusChanged(new DeviceChangeEventArgs(
                                                newReaderList.ToList(),
                                                attached,
                                                detached));
                        }

                        readers = newReaderList;

                        var scannerStates = new[] {
                            new SCardReaderState {
                                ReaderName        = "\\\\?PnP?\\Notification",
                                CurrentStateValue = (IntPtr)(readers.Count << 16),
                                EventStateValue   = (IntPtr)SCRState.Unknown,
                            }
                        };

                        var rc = _ctx.GetStatusChange(SCardContext.INFINITE, scannerStates);
                        if (rc == SCardError.Cancelled)
                        {
                            return;
                        }

                        if (rc != SCardError.Success)
                        {
                            throw new PCSCException(rc);
                        }
                    } catch (NoServiceException) {
                        noServiceCount++;
                        if (noServiceCount > 10)
                        {
                            throw;
                        }
                        // Windows 10, service will be restarted or is not available after the last reader has been disconnected
                        Thread.Sleep(1000);
                        lock (_gate) {
                            _ctx?.Dispose();
                            _ctx = _contextFactory.Establish(_scope);
                        }
                    }
                }
            } catch (Exception exception) {
                OnMonitorException(new DeviceMonitorExceptionEventArgs(exception));
            }
        }