/// <summary> /// Initializes a new instance of the <see cref="SmartCardReaderChooser"/> class. /// </summary> public SmartCardReaderChooser() { InitializeComponent(); Application.ApplicationExit += (s, _) => { Action <Action> t = a => { try { a(); } catch { } }; if (reader != null) { t(() => reader.CloseCard()); t(() => reader.Dispose()); reader = null; } }; readersBox.SelectedValueChanged += (s, _) => RefreshUI(); refreshReadersButton.Click += (s, _) => FillReadersList(); openCardButton.Click += (s, _) => OpenCard(); closeCardButton.Click += (s, _) => CloseCard(); }
private void OpenCard() { var name = readersBox.SelectedItem as string; if (string.IsNullOrEmpty(name)) { return; } if (reader != null) { reader.Dispose(); reader = null; } try { reader = PcscSmartCardReaderFactory.CreateDevice(name); reader.OpenCard(); Program.Log(string.Format("Card Opened: {0}", reader.IsCardOpened)); OnSmartCardReaderConnected(); } catch (Exception ex) { Program.LogException(ex); if (reader != null) { reader.Dispose(); } reader = null; } RefreshUI(); }