本文介绍了智能卡读卡器插件(插入卡)事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
背景:
我正在创建一个 Windows 10 通用应用,它从智能卡(插入智能卡读卡器)读取一些数据并且它工作正常,但在所有情况下,用户都应该触发该过程从卡中读取数据.
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.
问题:
如何处理 UWP 中的卡插入事件",以便每次插入卡后都能从卡中读取数据?
How can I handle the 'Card Inserted Event' in UWP, so I can read data from card each time after it is inserted?
推荐答案
我不熟悉 UWP,但我发现了这个 示例.
I am not familiar with UWP but i found this example.
它创建了一个智能卡读卡器实例:
It creates a smartcard reader instance:
private SmartCardReader reader = provisioning.SmartCard.Reader;
并向其添加一个 CardAdded
处理程序:
and adds a CardAdded
handler to it:
reader.CardAdded += HandleCardAdded;
HandlerCardAdded
看起来像这样:
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);
}
希望对你有所帮助.
这篇关于智能卡读卡器插件(插入卡)事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!