0
我有一個Paragraph
對象,我嘗試從與創建它不同的線程訪問,然後發佈我的問題在此處搜索一個在線解決方案,我發現了「Dispatcher」解決方案,這對我來說不管用。調用線程無法訪問此對象,因爲不同的線程擁有它,即使在使用調度程序時
下面的代碼:
Run r = new Run((string)name + Environment.NewLine);
r.Foreground = Brushes.Green;
Dispatcher.Invoke(new Action(() => { currentlyOnlineParagraph.Inlines.Add(r); }), DispatcherPriority.ContextIdle);
我得到這個錯誤:
InvalidOperationException was unhandled An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll Additional information: The calling thread cannot access this object because a different thread owns it.
我怎樣才能解決這個問題?
謝謝,它的工作! –
歡迎你。我很高興它給出了修復 –