다음을 통해 공유


How to Capture Smart Card Added and Card Removed Events In Windows Store Apps

I’ve modified the sample smart card app (C# version) and upload the code here https://github.com/zxue/Windows-universal-samples/pull/1/files 

For more info on smart card and minidriver info, check https://msdn.microsoft.com/en-us/library/windows/hardware/dn468773(v=vs.85).aspx

image image

1. Capture and Display Card ID

Adding a new property to the code and modify the user interface

image

image

2. Respond to user actions – when the card is inserted into the reader or the card is removed from the reader

a) Move most code from ListSmartCard_Click to a private method

image

b) Add one line code to use current window or page Dispatcher. This line fix the error that would occur, “The application called an interface that was marshaled to a different thread.”

await rootPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {

image

c) Add two lines of code to listen to two events: Reader_CardAdded and Reader_CardRemoved

reader.CardAdded += Reader_CardAdded; // should fire when the card is inserted or touches the reader
reader.CardRemoved += Reader_CardRemoved; // should fire when the card is removed or moves out of range from the reader

image

That’s all.