Smart Card Reader Plugin (Card Inserted) Event

2019-05-28 05:00发布

Background:

I'm creating a Windows 10 Universal App which reads some data from smart card (inserted into smart card reader) and it is working properly, but in all cases, the user should trigger the process to read data from card.

Question:

How can I handle the 'Card Inserted Event' in UWP, so I can read data from card each time after it is inserted?

1条回答
Rolldiameter
2楼-- · 2019-05-28 05:21

I am not familiar with UWP but i found this example.

It creates a smartcard reader instance:

private SmartCardReader reader = provisioning.SmartCard.Reader;

and adds a CardAdded handler to it:

reader.CardAdded += HandleCardAdded;

The HandlerCardAdded looks like this:

void HandleCardAdded(SmartCardReader sender, CardAddedEventArgs args)
{
    // This event handler will not be invoked on the UI thread.  Hence,
    // to perform UI operations we need to post a lambda to be executed
    // back on the UI thread; otherwise we may access objects which
    // are not marshalled for the current thread, which will result in an
    // exception due to RPC_E_WRONG_THREAD.
    uiContext.Post((object ignore) =>
    {
        rootPage.NotifyUser("Card added to reader " + reader.Name + ".", NotifyType.StatusMessage);
    }, null);
}

Hope this helps you a little.

查看更多
登录 后发表回答