Running Modules in different threads

Apr 19, 2010 at 1:46 PM

Hello All,

             I am working on a project with CAL framework. I am facing the issue that one of my modules has a WPF Web Browser control. Sometimes, when the web get stuck, the entire application get stuck too! Is there any way to run the modules in a different thread?


Many Thanks!

Apr 19, 2010 at 7:51 PM


Prism does not provide this capability out of the box, but it should be achievable by initializing the modules in different threads (in the ModuleInitializer). This however, might be troublesome, as there could be some complexities interacting with the UI.

Take into account that as WPF has a single UI Thread for its application, running the module in a different thread might not solve your problem if the WPF Web Browser is causing it. If the cause of the issue is not the specific control, running the operations that are causing the delay in another thread/asynchronously might bring some improvement. The Reactive Extensions for .NET (Rx) might be useful for you in this case.

Please let me know if this helps.

Damian Schenkelman

Apr 19, 2010 at 8:48 PM

Thanks Damian,

                            My issue is that i have a WPF web Browser embedded in one module, and with some popups, it freezes. The issue is that the entire GUI freezes and not allowing me to kill that module only causing the application to crash.


I tried to create the WebBrowser control from another thread but i am receiving the exception "The calling thread must be STA, because many UI components require this."


I want to figure out a way that a if a module freezes, the entire application could keep working.





Apr 19, 2010 at 10:18 PM

Try opening your WPF window with the browser control on a separate thread. This way the window will have its own message pump and it won't block the entire application if the window freezes.


            threadBrowser = new Thread(new ThreadStart(ShowBrowser));
            threadBrowser.Name = "Browser";

        void ShowBrowser()
            myWindow = new MyBrowserWindow();
            myWindow.Closed += (s, e) => { myWindow.Dispatcher.InvokeShutdown(); myWindow = null; };

Apr 21, 2010 at 2:44 PM

I tried it, but as i create the Window (in this case a Control) in another thread, i can inject the view into the RegionManager that is running in another thread.. :(


I tried also to create the Window and the WebBrowser control in other thread, but it fails while injecting the WebBrowser control into the Window...


Any ideas?