In a WPF application I had a BackgroundWorker thread creating an object. Let's call the object foo.
Background worker code:
SomeClass foo = new SomeClass();
// Do some operation on foo
// Set some dependency property on the main class to foo
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(SendOrPostCallback)delegate { SetValue(FooProperty, foo); },
foo);
Now, when the main class tries to access FooProperty using a getter, I get an InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
If the thread the create the object is finished, why does it still own the object? Is there someway around this.?