0

I am in learning multithreading (and related stuff like concurrency, TPL - in .NET, Windows) and hope that thу answers to this question would significantly reduce the amount of my doubts.

Why WPF UI requires output (from multiple threads) through the Dispatcher while the console does not?
I hope that this explanation will be a little more detailed then the overused and underdefined in MSDN docs phrase that Console class is thread-safe (or better to avoid the use of ambiguous terms at all).

Update:
Thanks to Justin Pihony's comment, sub-question:
Why reading from WPF UI is not possible without a Dispatcher object while Windows Forms permit both reading and writing without Invoke/BeginInvoke?
Why (or how) does reading compromise thread-safedty of WPF UI?

I am trying to disambiguate for me the phrase from Parallel Programming in .NET Framework 4: Getting Started :

"I didn’t have problems with the console application because the Console class is thread safe. But in WPF, UI components can be safely accessed only by a dedicated UI thread"

Proposed topics for reading the answers:

Community
  • 1
  • 1
Fulproof
  • 4,466
  • 6
  • 30
  • 50
  • 1
    What did you try looking up already? http://stackoverflow.com/questions/10450750/can-you-access-ui-elements-from-another-thread-get-not-set Brian's answer should suffice for what you want – Justin Pihony Apr 03 '13 at 01:35
  • If you believe that "thread-safe" is ambiguous and underdefined, you have much more reading to do. – Chris Hayes Apr 03 '13 at 02:05
  • 1
    The linked SO questions point to why WPF UI has that threading model. The Console choice is touched on with this one: http://stackoverflow.com/questions/1079980/calling-console-writeline-from-multiple-threads – James Manning Apr 03 '13 at 02:21
  • @HighCore, I do not see how your reference makes my question the duplicate. Why doesn't console require the Dispatcher object? – Fulproof Apr 03 '13 at 02:21
  • 1
    Even in console, improper use of `Threading` across `object` can be unsafe, the reason console do not need a `Dispatcher` is because it `read/writes` to `input/output` stream (Stdin, Stdout). – Parimal Raj Apr 03 '13 at 02:26

1 Answers1

0

WPF/WinForm create and use window, which has affinity on single threading.

console don't use window, it just output/reply string.

it's "by design of window development".

Kelmen
  • 1,053
  • 1
  • 11
  • 24