The calling thread cannot access this object because another thread belongs to it.

I have a WPF window in the main thread. On the clock buttons of this window, I upload data. In the meantime, I am using a separate thread to display the standby screen. But I can not set the main window as the parent of the standby screen. This causes the following error: The calling thread cannot access this object because another thread belongs to it

+5
source share
3 answers

You want to learn the method Dispatcher.Invoke.

+7
source

BackgroundWorker ; , . , .

.

Dispatcher.Invoke :

private void DoStuffOnThread()
{
    Dispatcher.Invoke(new Action(DoStuffOnUIThread));
}

private void DoStuffOnUIThread()
{
    // ...
}
+5

, , , / ( "" ), .

, , . , , Invoke.

WPF ( 4 ):

http://msdn.microsoft.com/en-us/magazine/cc163328.aspx

0

All Articles