背景:
我正在创建一个Windows 10 通用应用程序它从智能卡(插入智能卡读卡器)读取一些数据并且工作正常,但在所有情况下,用户都应该触发从卡读取数据的过程。
问题:
如何在 UWP 中处理“卡插入事件”,以便每次插入卡后都可以从卡中读取数据?
我不熟悉 UWP 但我发现了这个example https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/SmartCard/cs/Scenario1_ProvisionTPM.xaml.cs.
它创建一个智能卡读卡器实例:
private SmartCardReader reader = provisioning.SmartCard.Reader;
并添加一个CardAdded
它的处理程序:
reader.CardAdded += HandleCardAdded;
The 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);
}
希望这对您有一点帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)