简体   繁体   中英

Cross-threading error/ Unresponsive UI

I have a WPF application in which I have a MainWindow under UI thread. I have created a thread in which I create another window. I have to create this window in a thread because it has to be updated continuously. I want the owner of this window to be the MainWindow. So I am using Dispatcher.Invoke to set the owner of this window.

But when I use Dispatcher.Invoke to access Main UI Thread from Thread 2, I get a cross thread access exception.

I'll post some sample code very soon. Until then, if someone has any idea, please share it.

This is my actual problem to which I thought of implementing above mentioned approach:

I have three line charts with 4 line series each in a window which are updated at an interval of 100 ms which I am doing using Dispatcher.Invoke. Because of this, the UI becomes kind of slow and unresponsive sometimes

I have created a thread in which I create another window.

That already isn't a very good idea and is prone to a lot of problems. All windows in your application should be created by the main "GUI" thread.

I have to create this window in a thread because it has to be updated continuously.

There are ways to achieve that without creating the window on another thread. Create your window on the main thread, then use a background thread to update it. That background thread can update your new window by using Dispatcher.Invoke .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM