来自HRESULT的Windows Phone异常:0x8001010E(RPC_E_WRONG_THREAD)

时间:2015-08-18 16:52:10

标签: c# windows-phone-8 windows-runtime windows-phone-8.1 windows-phone

我的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)

1 个答案:

答案 0 :(得分:4)

您需要先发送它:

Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            tbx.Text = data;
        });
编辑:显然,这并不总是最好的解决方案。如果您仍然收到该错误,请执行此操作:Run code on UI thread in WinRT