1

I have several projects, each of thern have UserControl to manage them. All projects are in one solution and working simultaneously. all UserControls are in TabControl. But if one project don't handle his exception, all solution fail down. How can i run each UserControl in another Thread ?

I have several classes, they are models in MVVM. All of them have ViewModel and View. Now all classes start and workig in one thread. If one of then throw exception< all app will fail down. I want taht all models working in individual thread. But all Views of taht models are together in TabControl. How i can organize this sheme?

Vader
  • 21
  • 3
  • 3
    Threads have _nothing_ to do with error handling. Threading will not help you at all. – SLaks Jun 26 '13 at 15:32
  • It sounds like you have the wrong mindset about "projects" and "solutions". They aren't "working simultaneously", they simply provide classes and methods that can be called on. Your program still boils down to a single `Main` method which calls other code procedurally. – nmclean Jun 26 '13 at 18:33

1 Answers1

3

You can't. WPF has one, and only one, user interface thread. Modifying user interface elements from a background thread won't work and will raise an exception. (EDIT: This is not entirely correct, apparently it is possible to start individual windows in their own threads.)

If you have a problem with uncaught exceptions, have a look at the Application.DispatcherUnhandledException event, which allows you to register a central exception handler for your complete WPF application. If you set e.Handled = true; at the end of your DispatcherUnhandledException handler, exceptions will cause your application to fall back to the user interface rather than terminating the application.

More information:

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • I find this - http://eprystupa.wordpress.com/2008/07/28/running-wpf-application-with-multiple-ui-threads/ There is several threads. – Vader Jun 27 '13 at 06:45
  • @Vader: Thanks for the link, that was an interesting read! Still, I stand by my main point that if exception handling is your problem, multi-threading is not the correct solution (and will, in the long run, create more problems than it solves if used for that purpose). – Heinzi Jun 27 '13 at 07:01