/// <summary> /// Enumerates NFC reader and registers event handlers for card added/removed /// </summary> /// <returns>None</returns> private async void GetDevices() { try { reader = await CardReader.FindAsync(); if (reader == null) { PopupMessage("No Readers Found"); return; } reader.CardAdded += CardAdded; reader.CardRemoved += CardRemoved; } catch (Exception e) { PopupMessage("Exception: " + e.Message); } }
private static async void OnCardAdded(SmartCardReader sender, CardAddedEventArgs args) { try { await HandleCard(args.SmartCard); // Raise on UI thread context.Post(_ => { var evt = cardAdded; if (evt != null) evt(sender, EventArgs.Empty); }, null); } catch (Exception ex) { // TODO: Add logging Debug.WriteLine(ex); } }
private static void OnCardRemoved(SmartCardReader sender, CardRemovedEventArgs args) { lock (cardConnectionLock) { if (currentConnection != null) { currentConnection.Dispose(); currentConnection = null; currentCardId = null; } } // Let users know the card is gone // Raise on UI thread context.Post(_ => { var evt = cardRemoved; if (evt != null) evt(sender, EventArgs.Empty); }, null); }
public static async Task Initialize() { // Clear out any old event handlers cardAdded = null; cardRemoved = null; if(reader != null) return; context = SynchronizationContext.Current; var r = await CardReader.FindAsync(); if (r != null) { reader = r; reader.CardAdded += OnCardAdded; reader.CardRemoved += OnCardRemoved; } }