I've been trying to use GraphSharp to display the hierarchical relation between different datasets. This all works fine until I start adding datasets at runtime. At some point in the adding process I get the following exception
System.InvalidOperationException was unhandled
Message=The calling thread cannot access this object because a different thread owns it.
at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
at GraphSharp.Controls.GraphLayout`3.CreateVertexControl(TVertex vertex)
at GraphSharp.Controls.GraphLayout`3.b__24(Object s, RunWorkerCompletedEventArgs e)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
From the looks of it this happens because GraphLayout.Graph is a dependency property on a UI control which is being accessed by a non-UI thread. The interesting thing is that I call the NotifyPropertyChanged method on the UI thread but then graphsharp pushes
the layout updating onto a background thread (which is obviously not the UI thread).
Does anybody know how to solve this problem? I suspect that either graphsharp has to get the graph through a non-dependency property or some of the work has to be moved to the UI thread.