In my main wpf Window I instantiate a new wpf window at a click of a button, that collects a bunch of data. This data is stored in a class object (see below).
Now when I try to pass this class to a backgroundworker I get the well-known “The calling thread cannot access this object because a different thread owns it.” error.
I can’t see how I can get around this problem. I feel I have tried every possible permutation without success.
The data are as follows:
internal int screenHeightInPixels; internal int screenWidthInPixels; internal double screenHeightInDpi; internal double screenWidthInDpi; internal List<System.Windows.Shapes.Rectangle> rAreas = new List<System.Windows.Shapes.Rectangle>(); internal Ellipse eAreas = new Ellipse(); internal List<System.Drawing.Color> Colors = new List<System.Drawing.Color>();
Where selector is the instantiation of the Selector window that retrived the data.
To test, in the DoWork I start with the following, which results in the error, in the second line.
selectedData = (SelectedData)(((SelectedData)e.Argument)); double d = selectedData.areas.Width;
Hope this is a trivial problem for a great mind out there.