Click here to Skip to main content
13,357,973 members (55,961 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 3 Nov 2010

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

, 13 Nov 2010
Rate this:
Please Sign up or sign in to vote.
Calling thread cannot access this object because a different thread owns it
Today I faced an issue with my custom control which has my own DictionaryList with custom CustomKeyValuePair class as Value of dictionary list. Key is a string type, so no problem on it. I used this dictionary list for storing resources to provide different skin support in my control template. Note the point, my CustomKeyValuePair class inherited from DependencyObject. After implementing my control with effective skin mechanism, I tried to host my control in multi threaded WPF application. But unfortunately, I got this error message {"The calling thread cannot access this object because a different thread owns it."} since calling thread uses my dictionary list Value(CustomKeyValuePair). As I said, this class inherited from DependencyObject, so WPF won't allow you to access dependency property in multi thread application.

Initially I tried to solve this issue with value cloning logic. But no use. Finally, I tried with INotifyPropertyChanged class. Yes, I just removed base class DependencyObject from CustomKeyValuePair class and implemented INotifyPropertyChanged interface with Value property notification when its value getting changed. Now my controls work in multithread WPF application perfectly. :)

public class CustomKeyValuePair : INotifyPropertyChanged //DependencyObject
//public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(PairKeyValue), new UIPropertyMetadata(null));

//public object Value
// get
// {
// return (object)GetValue(ValueProperty);
// }
// set
// {
// SetValue(ValueProperty, value);
// }

// Solution for "The calling thread cannot access this object because a different thread owns it."

object _value;

/// <summary>
/// Gets or sets the value in key-value pair.
/// </summary>
public object Value
return _value;
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

Enjoy :)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Logitech Engineering & Design (India) Pvt. Ltd.
India India
Venugopal works as a Senior Software Engineer in Logitech Engineering & Design (India) Pvt. Ltd. He hold a Masters in Computer Applications and has 4+ years experience in C#, XAML, Silverlight & WPF.

Venugopal firmly believes "technology is impermanent, change is not"!. While he has strong technical inclination towards MS technologies, he is deeply passionate about pursuing his career in Windows7-WPF and Silverlight Technology.

Venu engages in a wide gamut of temperamental hobbies ranging from making friends, traveling, helping his friends studies. To murmuring songs and watching movies in leisure time.

You may also be interested in...

Comments and Discussions

QuestionAnimations. Pin
hannes.ambichler14-Sep-12 20:01
memberhannes.ambichler14-Sep-12 20:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by venugopalm
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid