智能卡读卡器插件(卡插入)事件

时间:2016-11-24 12:13:59

标签: c# .net win-universal-app windows-10-universal smartcard-reader

背景

我正在创建 Windows 10 Universal App ,它从智能卡中读取一些数据(插入智能卡读卡器)并且工作正常,但在所有情况下,用户都应该触发从卡读取数据的过程。

问题:

如何处理卡插入事件'在UWP中,每次插入数据后我都可以从卡中读取数据吗?

1 个答案:

答案 0 :(得分:1)

我对UWP并不熟悉,但我发现了example

它创建了一个智能卡读卡器实例:

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);
}

希望这对你有所帮助。