Smart Card Reader Plugin (Card Inserted) Event

岁酱吖の 提交于 2019-12-07 21:00:29

问题


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:


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.



来源:https://stackoverflow.com/questions/40786160/smart-card-reader-plugin-card-inserted-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!