Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

346
Visualizações
Difference between Async/Await and Dispatcher

I am working on a WPF application and I am running into freezing issues, by now I have learned that its a single threaded application, but i am getting confused with terminologies

I simple terms

Difference between Async/Await and Dispatcher

I want to explain my point of view so its clear on both ends my misunderstanding , until now I have learned that most applications are STA (in c#), and you have to use asynchronous programming, which can very well involve

  • A single thread that shifts work on the UI thread by prioritizing work that has already completed and then using a worker thread to notify the UI thread that the heavy work is done
  • Also a truly multi threaded application where a thread needs to be created to complete the task on it

I think for most part my concept is at least solid to say the least where I lack is applying these abilities

for instance i though that previously to enable asynchronous programming we had to use delegates to be called from the main method, which evolved into a dispatcher cutting of delegates which further evolved into async and await cutting 'ANY SINGLE USE OF' dispatcher (even that literal keyword)

so all i used were "async" word at the declaration of the function, followed by the "task", then awaiting some intense process by sticking an "await" word before it finally encapsulating that intense work with Task.Run(() => IntenseWork())

but now I am confused that you have to use Dispatcher word because UI elements can only be accessed by dispatcher , and use Dispatcher.Invoke(IntenseWork()), then there is Dispatcher.Begininvoke and Dispatcher.AsyncIncoke

DOUBT:

in which case async/await and task.run isn't going to be enough and is task parallel library even going to be used here


I asked questions and reserched and am stuck at these conclusions, these r my previous questions

Asynchronous Navigation

Using async and await to achieve asynchronicity in example problem

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are asking about two different technologies from different periods.

The common problem is that the UI is single threaded and should only be accessed from the main (UI) thread.

You can and should offload non-UI work to another thread as much as possible. But there usually are results that need to be displayed afterwards.

The old (but still valid) approach is to hand a delegate to Dispatcher.Invoke(), or Control.Invoke() in WinForms.

The newer approach, applicable to Task.Run() and all DoSomethingAsync() I/O methods is to use await:

// use async void only for eventhandlers
async void LoadButton_Click(object s, RouteEventArgs e)
{
   // get input from controls here
   var results = await Task.Run(() => HeavyWorkWithoutUI());
   // update UI with results here
}

The WPPF and WinForms support is that your toplevel methods will run on the UI thread before and after an await. The heavy method will run on another thread. During the await your UI remains responsive.

So await is just a little more convenient, letting you write more readable code with less effort.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda