Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF LifeCyle in an Add-in
    primarykey
    data
    text
    <p>I've created an add-in, which call via Reflection, a WPF Class Library. Since this is a class library, I had to instanciate manually a <code>new System.Windows.Application()</code>.</p> <p>Then, the class constructor (the one called via reflection) create a window, and Show() (with Dispatcher.Run() to avoid the window to close immediately) or ShowDialog().</p> <p>Since my application is into an add-in, Application is still alive. Therefore, I can instanciate this only once.</p> <p>On the first launch (when Application is instanciated), the Application.Current.Dispatcher is Running.</p> <p>But on the second launch, I firured out that the Application.Current.Dispatcher was Stopped. I never call InvokeShutdown() so I don't understand when the Dispatcher is stopped.</p> <p>When I launch this a second time, Application is already instanciated (it's normal) but Dispatcher stopped.</p> <p>Any idea ? Thanks !</p> <p><strong>Edit :</strong> In my Add-in, I've tried 2 ways :</p> <p><em>First way :</em> </p> <pre><code> foreach (Type type in ass2_l.GetTypes()) { if (type.Name == "Loader") { object obj_l = Activator.CreateInstance(type); BindingFlags bf_l = BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; object[] argList_l = new object[1]; argList_l[0] = "ok"; type.InvokeMember("Load", bf_l, null, obj_l, argList_l); } } </code></pre> <p>When I call directly the dll from the add-in, Application.Current.Dispatcher is in Background State, with name "VSTA_Main". When I launch a second time, Dispatcher is still in background state.</p> <p><em>Second way :</em> </p> <pre><code> t_m = new Thread(loadDll); t_m.SetApartmentState(ApartmentState.STA); t_m.Start(); </code></pre> <p>loadDll actually contain the same code of the "first way" code. When I launch this part for the first time, the Dispatcher is Running, and all is perfectly normal. When launched the second time, Dispatcher is stopped.</p> <p><strong>EDIT 2 :</strong> The problem is in the second way. When loadDll is finished and then I click again on my add-in button, t_m is stopped and creating another one don't resolve the problem since the Dispatcher ManagedThreadId has the old t_m ManagerThreadId :/</p> <p><strong>EDIT 3 :</strong> The problem is definately not caused by the Add-in. If you Just create a program that launch a thread everytime you click on a button. The thread try to instanciate a DLL WPF Class Library (by reflection), and if you click a second time on this button (calling another thread), as the Dispatcher is still "linked" to the old thread, the Dispatcher is "stopped" (like the old thread)</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