智能卡 Reader 插件(已插入卡)事件
Smart Card Reader Plugin (Card Inserted) Event
背景:
我正在创建一个 Windows 10 通用应用程序,它从智能卡中读取一些数据(插入智能卡 reader)并且它正在运行正确,但在所有情况下,用户都应触发从卡中读取数据的过程。
问题:
如何处理UWP中的'Card Inserted Event',以便每次插入卡后都能从卡中读取数据?
我不熟悉 UWP,但我发现了这个 example。
它创建一个智能卡reader实例:
private SmartCardReader reader = provisioning.SmartCard.Reader;
并向其添加一个 CardAdded
处理程序:
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);
}
希望对您有所帮助。
背景:
我正在创建一个 Windows 10 通用应用程序,它从智能卡中读取一些数据(插入智能卡 reader)并且它正在运行正确,但在所有情况下,用户都应触发从卡中读取数据的过程。
问题:
如何处理UWP中的'Card Inserted Event',以便每次插入卡后都能从卡中读取数据?
我不熟悉 UWP,但我发现了这个 example。
它创建一个智能卡reader实例:
private SmartCardReader reader = provisioning.SmartCard.Reader;
并向其添加一个 CardAdded
处理程序:
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);
}
希望对您有所帮助。