Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access object from another thread
    primarykey
    data
    text
    <p>I understand that this has been discussed on other questions but I am pulling my hair out here- clearly missing something obvious. I'll try to give you some background info so here goes...</p> <p>I have a UI thread which was freezing up so I created a background worker to do all the heavy processing to keep my UI interactive.</p> <p>I need to generate coordinates for some arcs/ paths which I then draw on a canvas. The background worker processes and runs it's work completed method where it stores the PathGeometry along with some other data in a list. I then called an update() method in my UI thread, from my backgroundworker, using the object I passed into the backgroundworker.</p> <p>My problem is that when I begin to build the Path objects in the UI thread (it wouldn't let me build them in the backgroundworker thread) I am unable to access the PathGeometries. My object is a CommunicationArc and it holds the PathGeometry, opacity, colour etc.</p> <pre><code>The calling thread cannot access this object because a different thread owns it. </code></pre> <p>I can access other parts of the object but <strong>not</strong> the PathGeometry and I do not know why. The backgroundworker surely has finished as the workcomplete method has run and the Arcs are all stored in my list. I simply want to read the arcs in my UI thread, process them a little bit more and go on to draw them.</p> <p>I have tried using the Dispatcher from my UI thread like so:</p> <pre><code>arc.pathGeometry.Dispatcher.BeginInvoke((Action)(() =&gt; { MessageBox.Show(arc.pathGeometry.ToString()); })); </code></pre> <p>But I'm not really sure if what I am doing is right and various methods to call the Dispatcher either don't do anything or lock everything on the BeginInvoke().</p> <p>Any help would be great, I feel like I'm going in circles here!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload