0

The second answer by Martin in this link explains how the dispatcher can be used in a winforms app. This link explains the wpf side. So my question is - can we do this in a winforms app ? If not, why ? thank you

UPDATE: I have found this link also that shows the multiple app.run method mentioned by Henk below. However it does not use the wpf dispatcher. I wonder if there is a performance diff between using the wpf dispacther in winforms (my question) vs multiple app.runs

Community
  • 1
  • 1
Gullu
  • 3,477
  • 7
  • 43
  • 70
  • The big question: Why? You can start a 2nd thread wtih App.Run in WinForms but that never seemed a good idea either. – H H Sep 29 '11 at 15:04
  • Same reason as mentioned in the link I have posted. Pasting here. "In a very UI intensive application (for example, trading app with about ten windows showing real-time montage and blotter data) simply the cost of generating and laying out visuals can become too high for a single thread to keep up." – Gullu Sep 29 '11 at 17:51

1 Answers1

1

No matter what you do, you will be limited to using 1 thread (the UI thread) to update your windows (Winforms, WPF, native code). You can spawn as many worker threads as you want to do all the data gathering and prep work you need, however you'll still have to use the UI thread to do the updates. Take a look at the Task or the BackgroundWorker classes to do this work.

Bahri Gungor
  • 2,289
  • 15
  • 16
  • 1
    the article link I posted in my question clearly demos how you can create a separate message pump/UI thread for each window. It has like 16 votes and a lot of praise at the bottom comments. It is the first article you get when you google for "multiple ui threads". What am i missing here ? thanks – Gullu Sep 29 '11 at 18:56
  • @Gullu I see, so you just want one message loop per window. I would avoid mixing the technology at this level. There are a lot of issues with integrating WinForms with WPF (in either direction), and I think mixing them at this level will just introduce unnecessary complexity. Yes, Application.Run(form) will work for WinForms, Dispatcher.Run() will work for WPF. In either case the message loop is created and executed, satisfying your question. – Bahri Gungor Sep 29 '11 at 20:13