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 199703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:02:48+00:00 2026-05-11T17:02:48+00:00

We have a desktop application that performs a pretty rigorous set of calculations in

  • 0

We have a desktop application that performs a pretty rigorous set of calculations in a background thread. Portions of this calculation are performed in an unmanaged library that we access through interop. What we are finding is that, when we kick off the calculation, the UI thread becomes unresponsive for the duration of the calculation. We were under the impression that the framework would handle the thread switching to permit the UI to continue to be responsive, but that is not the case. We have found that we can insert a Thread.Sleep(0) or Application.DoEvents() to permit the UI to be responsive. This has the side effect of slowing the calculation. Also, portions of the calculation performed by the unmanaged code can take up to 30 seconds to complete, and during this time the application is always unresponsive. The entire calculation can take anywhere from two to five minutes to complete.

This leads to the following questions:

  • What is the .NET framework threading model with regard to the UI and interop?
  • Are we incorrect in assuming that the framework should handle thread switching between the background and UI threads?
  • What is the difference between using Thread.Sleep and Application.DoEvents in this situation, and is one preferred over the other?
  • 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-11T17:02:48+00:00Added an answer on May 11, 2026 at 5:02 pm

    You could lower the priority of your background thread, so it will be preempted more by the OS. If you have some domain knowledge that leads you to want to control when it’s preempted, you could go with Thread.Sleep(0) which surrender your timeslice if there’s another thread waiting.

    Application.DoEvents pumps the windows message queue. This will cause your app to respond to events like keystrokes or window resizes. Thread.Sleep will cause your thread to be preempted (or maybe not, in the case of Thread.Sleep(0)).

    Also read Threading in C#

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

Sidebar

Related Questions

I have a desktop (winforms) application that uses a Firebird database as a data
Now that I know C++ I want to get into desktop application that have
I have a custom class loader so that a desktop application can dynamically start
I have heard mention that some desktop applications are pretty much just wrappers for
I have a major problem. We have a asp.net application that has this report
I have a Java web application that has a 'disconnected' Java Swing desktop app.
I have a desktop application written in Ruby that is using GTK2. It's just
I have a fairly simple desktop application that uses a .NET setup project (.msi
I have a desktop application that on first execution prompts for the connection details
Hopefully easy question, I have a desktop application that allows the user to upload

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.