WPF – The calling thread cannot access this object because a different thread owns it

We can’t update the WPF UI components from a thread, that is not owning the UI Component. When we try to update any UI elements from another thread, we will get the exception

“The calling thread cannot access this object because a different thread owns it”

We can achieve this functionality using the Dispatcher. Following code tries to bind the data to the View[custom control] control from another thread.

View.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(delegate()
{
View.DataContext = Data;
}
));

About ambilykk

I am a Technology Evangelist on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Azure and Visual Studio. Technology adoption and learning is my key strength and technology sharing is my passion.
This entry was posted in WPF. Bookmark the permalink.

4 Responses to WPF – The calling thread cannot access this object because a different thread owns it

  1. US says:

    Thanx for these post. I have been struggling for these since two days !!!
    You saved my life !

  2. Thomas says:

    I Used Dispatcher But the Same error Still there..

  3. Thomas says:

    I Used Dispatcher But the Same error Still there.. please help me

  4. disc says:

    And where should i copy this snippet?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s