簡體   English   中英

更改 ObservableCollection 時 Xamarin.Forms UWP (Windows) 應用程序中的 System.Runtime.InteropServices.COMException

[英]System.Runtime.InteropServices.COMException in Xamarin.Forms UWP (Windows) App when changing ObservableCollection

I have a Xamarin.Forms app (.NET Standard 2.0, Xamarin.Forms 4.8), which so far I have only used for the Android project, which is working like a charm. 不過,我剛剛重新激活了 UWP(通用 Windows)項目,它也編譯得很好,但是當我嘗試運行它時,我填充的第一個 ObservableCollection(從主頁的 OnAppearing 觸發)會導致上述異常:

System.Runtime.InteropServices.COMException

HResult=0x8001010E

應用程序調用了為不同線程編組的接口。 [德語原始消息:Eine Schnittstelle, die für einen anderen Thread marshalled war, wurde von der Anwendung aufgerufen。] HRESULT 異常:0x8001010E (RPC_E_WRONG_THREAD)

我一般都知道這種類型的錯誤信息(我在其他項目中一直遇到它們^^),因為列表的更新不會發生在UI線程上,因此數據綁定不愉快。 通常我會將它包裝在一些調度程序中(我的研究特別建議使用Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync )。 除了處理實際列表的代碼當然在我單獨的 View Model 項目(.NET Standard 2.0)中,它應該與系統無關(因為它也被 Android 項目使用),並且提到的調度程序是 Windows 特定的,所以這個解決方案對我來說有點不可用。

我能做些什么來解決這個問題? 我可以在這里使用某種 Xamarin 或 .NET 標准調度程序嗎? 或者有沒有其他方法可以修改,UWP 應用程序如何......數據綁定或什么?

使用 Xamarin EssentialsMainThread助手

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM