Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot use a DependencyObject that belongs to a different thread than its parent Freezable - prism
    text
    copied!<p>I have came across a problem while developing a WPF application. The application is based on Prism. The application boots using the prism bootstraper and before loading any Window, the app opens a modal dialog on a different thread (STA), and then a bunch of stuff are loaded (services and etc.) The dialog is open during that time and allows to notify the user on the progress of the application start-up process (using event aggregator to pass the updates). When loading is done, bootstraper closes the dialog and opens the main application window. <em>So far so good...</em> Then when closing the application, same thing is going on. the Main window is closed, a dialog box is opened (again on a new STA thread), to allow notifications. But now, when hitting the ShowDialog call (which occurs inside the new STA thread), an exception is raised: "Cannot use a DependencyObject that belongs to a different thread than its parent Freezable". After long long hours of debugging I have figured out the cause for the exception was the background of the window which is a brush/image taken from a merged dictionary at the application level (instantiated on the wpf UI thread). If loading the image without a ResouceDictionary - everything goes well.</p> <hr> <p><em><strong>To summaries:</em></strong> The exception is observed only when using a resourceDictionary and only on the second call to a new STA thread which in turn loads up a DialogBox and raise an exception exactly when calling ShowDialog If you have only one dialog (for example no dialog at boot time and only dialog at the shutdown process), then the exception will not occur.</p> <hr> <p><em><strong>My question is then:</em></strong> what is the reason for that? what exactly this exception mean in this case? (I understand that in general there is some kind of UI thread updates form other threads, but then I do not understand why this happens only on the second instance of the dialgo+thread).</p> <p>Thanks :)</p>
 

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