Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 648893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:52:57+00:00 2026-05-13T21:52:57+00:00

I’m building a WPF application. I’m doing some async communication with the server side,

  • 0

I’m building a WPF application. I’m doing some async communication with the server side, and I use event aggregation with Prism on the client. Both these things results in new threads to be spawned which are not the UI thread. If I attempt to do “WPF operations” on these callback and event handler threads the world will fall apart, which it now has started doing.

First I met problems trying to create some WPF objects in the callback from server. I was told that the thread needed to run in STA mode. Now I’m trying to update some UI data in a Prism event handler, and I’m told that:

The caller cannot access this thread because a different thread owns it.

So; what’s the key to getting things right in WPF? I’ve read up on the WPF Dispatcher in this MSDN post. I’m starting to get it, but I’m no wizard yet.

  1. Is the key to always use Dispatcher.Invoke when I need to run something which I’m not sure will be called on the UI thread?
  2. Does it matter if it actually was called on the UI thread, and I do Dispatcher.Invoke anyway?
  3. Dispatcher.Invoke = synchronously. Dispathcher.BeginInvoke = async?
  4. Will Dispatcher.Invoke request the UI thread, and then stop to wait for it? Is it bad practice and risk of less responsive programs?
  5. How do I get the dispatcher anyway? Will Dispatcher.CurrentDispatcher always give me the dispatcher representing the UI thread?
  6. Will there exist more than one Dispatcher, or is “Dispatcher” basically the same as the UI thread for the application?
  7. And what’s the deal with the BackgroundWorker? When do I use this instead? I assume this is always async?
  8. Will everything that runs on the UI thread (by being Invoked) be run in STA apartment mode? I.e. if I have something that requires to be run in STA mode – will Dispatcher.Invoke be sufficient?

Anyone wanna clearify things for me? Any related recommendations, etc? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:52:58+00:00Added an answer on May 13, 2026 at 9:52 pm

    Going over each of your questions, one by one:

    1. Not quite; you should only invoke onto the UI thread when necessary. See #2.
    2. Yes, it does matter. You should not just automatically Invoke everything. The key is to only invoke onto the UI thread if necessary. To do this, you can use the Dispatcher.CheckAccess method.
    3. That is correct.
    4. Also correct, and yes, you do run the risk of less responsive programs. Most of the time, you are not going to be looking at a severe performance hit (we’re talking about milliseconds for a context switch), but you should only Invoke if necessary. That being said, at some points it is unavoidable, so no, I would not say it is bad practice at all. It is just one solution to a problem that you will encounter every now and then.
    5. In every case I have seen, I have made due with Dispatcher.CurrentDispatcher. For complex scenarios, this may not be sufficient, but I (personally) have not seen them.
    6. Not entirely correct, but this line of thinking will not do any harm. Let me put it this way: the Dispatcher can be used to gain access to the UI thread for the application. But it is not in and of itself the UI thread.
    7. BackgroundWorker is generally used when you have a time-consuming operation and want to maintain a responsive UI while running that operation in the background. Normally you do not use BackgroundWorker instead of Invoke, rather, you use BackgroundWorker in conjunction with Invoke. That is, if you need to update some UI object in your BackgroundWorker, you can Invoke onto the UI thread, perform the update, and then return to the original operation.
    8. Yes. The UI thread of a WPF application, by definition, must be running in a single-threaded apartment.

    There’s a lot to be said about BackgroundWorker, I’m sure many questions are already devoted to it, so I won’t go into too much depth. If you’re curious, check out the MSDN page for BackgroundWorker class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer EDIT: As pointed out by other users, the method I… May 14, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer You can overcome this easily in a local environment by… May 14, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer There is no need to set the KeyPreview Property to… May 14, 2026 at 3:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.