1

I understand the use of Application.Current.Dispatcher (It gives us the dispatcher related to the the Main Thread). But my doubt is regarding Dispatcher.CurrentDispatcher.

If the Dispatcher.CurrentDispatcher gives us the Dispatcher related to the currently running thread, then why do we even need to call it for invoking any action. We can just directly invoke our action by plainly calling the method.

Is it just needed to schedule the invocation of the action using DispatcherPriority?

Edit: I don't think that the marked question (duplicate) answered my exact question. The answer to that question differentiates between the two but my question asks why does one of them even exists.

  • [Dispatcher.CurrentDispatcher vs. Application.Current.Dispatcher](https://stackoverflow.com/questions/10448987/dispatcher-currentdispatcher-vs-application-current-dispatcher) – stuartd Mar 20 '18 at 14:36
  • 1
    What if you (or somebody else) create a thread with a dispatcher, and want to invoke something on this (dispatcher) thread from another thread? Your question is pretty much the same as asking: "_If i only execute code on the main/GUI thread, why would we even need to call through a dispatcher?_" ... –  Mar 20 '18 at 14:37
  • I don't think that the marked question (duplicate) answered my exact question. The answer to that question differentiates between the two but my question asks why does one of them even exists. – Atul Poddar Mar 20 '18 at 14:54
  • Can anyone please answer my question? Thanks in advance. – Atul Poddar Mar 20 '18 at 15:10
  • They can be different in an app that creates UI on more than one thread. Chicken-and-egg, if you don't really understand the difference then you should never ever do this. Fwiw, Dispatcher.CurrentDispatcher gets programmers chronically in trouble when they use it in a worker thread. So always favor Application.Current.Dispatcher – Hans Passant Mar 20 '18 at 17:13

0 Answers0