Devendra Kumar

Devendra Kumar

  • 1.5k
  • 415
  • 84.4k

Thread safe Dependency Property in WPF

Jun 11 2020 3:50 PM
Hello everyone,
I am working on a WPF project and found an issue ot thread calls.
I have a Dependency Property of a usercontrol as below
  1. public bool IsON  
  2.         {  
  3.             get { return (bool)GetValue(IsONProperty); }  
  4.             set { SetValue(IsONProperty, value); }  
  5.         }  
When I access this property, an exception occurs  "The calling thread cannot access this object because a different thread owns it"
I tried lock function with a readonly object but no luck.
Is there any solution to make it thread safe on user control side and not from the calling class because I want to handle it from usercontrol side, as the property was used several times

Brought to you by:

Answers (3)