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

  • SEARCH
  • Home
  • 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 1017011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:38:13+00:00 2026-05-16T10:38:13+00:00

According to Single-Threaded Application with Long-Running Calculation MSDN example, there is a possibility of

  • 0

According to Single-Threaded Application with Long-Running Calculation MSDN example, there is a possibility of creating a responsive GUI in just 1 thread. Thanks to the Dispatcher object, as we can set the Priority of work items.

My question is, what sense does it have to do simple tasks (supposing we just have 1 single core cpu) in a background thread when this is possible?

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-16T10:38:14+00:00Added an answer on May 16, 2026 at 10:38 am

    Essentially the example has broken up the single task of ‘finding as many prime numbers as you can’ into many, many fast running individual steps that are executed at a very low priority, so that they’re unlikely to interrupt a user interacting with the window.

    One drawback I feel is that it forces the programmer to break up a task into many small steps that we have to guarantee can be executed quickly. When one of those tasks is running, it’s blocking the UI for the entire duration of it. Consider downloading a file. Taking the single step of connecting to an FTP site could take 20 seconds or more, during which time the UI is frozen.

    Compare this with a proper thread doing the whole download in one go, marshalling updates back to the UI thread. Even on a single core machine this should provide a reasonable user experience.

    The next drawback is that you’re now executing code on a single thread. This isn’t as great as it sounds. Because of the way that the small individual tasks are being queued, other tasks (anything pushed onto the window’s message queue) have a chance to jump in and execute in amongst them. If the state that your special tasks use is not properly isolated, you can get issues that look like threading issues but aren’t, and worse still, you cannot protect yourself from those issues using locking, as all actions are performed on the same thread. There are similar drawbacks when using Application.DoEvents(), (although there’s some extra nasty stuff that can go on with that which can’t go on here).

    So the technique you outlined may be usable for some situations, and for some maybe not. I’d therefore go for the technique which is always applicable, which is running the code on a background thread.

    I think the answer is usually the same for most ‘use a single thread whilst keeping the UI responsive questions’. You can’t really. You have to bite the bullet and learn to thread properly. Think hard, isolate your state, protect state using immutability and locking, and marshal calls properly betweeen threads where needed.

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

Sidebar

Related Questions

According MSDN, FxCop is an application that analyzes managed code assemblies (code that targets
According to the Javadocs for Runtime here : Every Java application has a single
According to http://www.w3.org/TR/html401/interact/forms.html#h-17.4 , an input element should end with a single > and
There is a single WCF connection using TCP. Two threads on the server write
I have an MVC application with a single model and several views (something like
I would like to split a string according to the title in a single
I want to group multiple events in a single ICS file(iCalendar stream) according to
According to an example , I have three models: class User(models.Model): name = models.CharField(max_length=128)
According to the documentation JAXB factory methods do not have arguments. Is there a
According to http://www.javaworld.com/javaworld/jw-08-2007/jw-08-swingthreading.html?page=5 all GUI operations should be executed in Event Dispatch Thread. While

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.