我的Windows运行时应用程序读取NDEF NFC标签。
当应用程序读取NFC标签时,我的方法message received
将会打开。
private void messageReceived(ProximityDevice sender, ProximityMessage message)
{
device.StopSubscribingForMessage(NFCID);
var ndefMessage = NdefMessage.FromByteArray(message.Data.ToArray());
StringBuilder sb = new StringBuilder();
foreach (NdefRecord record in ndefMessage) sb.AppendLine(Encoding.UTF8.GetString(record.Payload, 0, record.Payload.Length));
String data= sb.ToString();
ShowData(data);
}
private void ShowData(string data)
{
tbx.Text = data;
}
当我想将此数据设置为文本字段时,每次抛出异常时: 来自HRESULT的异常:0x8001010E(RPC_E_WRONG_THREAD)
答案 0 :(得分:4)
您需要先发送它:
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
tbx.Text = data;
});
编辑:显然,这并不总是最好的解决方案。如果您仍然收到该错误,请执行此操作:Run code on UI thread in WinRT