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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:08:19+00:00 2026-06-04T07:08:19+00:00

All, I have a Task that runs on a background thread and does some

  • 0

All, I have a Task that runs on a background thread and does some heavy lifting. The way I have it set up is that whilst this is being done, the UI thread updates the GUI with progress information, some of which use animated .gif files. Take a look at the following example code to illustrate the problem

TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Task<bool> task = Task.Factory.StartNew(() => 
{
    // Heavy work.
    if (heavyWorkCompleted)
        MethodToUpdateGui(uiScheduler); // Update DataGridView ImageCell on UI thread
    // More work.
}

I have a “In Progress” image that is shown in the appropriate DGV image cell during execution of “Heavy Work”, if “Heavy Work” is successful this image changes to a tick (in DGV1), then MethodToUpdateGui(uiScheduler) uses this (just changed) image in DGV1 to update DGV2. However, when the MethodToUpdateGui(uiScheduler) runs it sometimes updates the DataGridView (DGV2) too fast. What I mean by this, is that the image is not the tick I want (and it should be due to successfull compleation) it is the “In Progress” image. It seems that the DGV is not updating fast enough for what I am doing.

Is there a better way to do this? Do I dare to spin the background thread after the GUI update to allow DGV1 to “catch-up” [this is nasty!]?

Thanks for your time.

  • 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-06-04T07:08:20+00:00Added an answer on June 4, 2026 at 7:08 am

    Is there a better way to do this? Do I dare to spin the background thread after the GUI update to allow DGV1 to “catch-up” [this is nasty!]?

    The issue here is that that TPL uses SynchronizationContext.Post to send the message to the UI thread. When the method runs, the Task will run asynchronously, which will, in turn, not update the GUI immediately.

    If you want to make sure that the GUI is updated, the simplest option would be to have your MethodToUpdateGui block by waiting on the Task scheduled via uiScheduler.

    This would look something like:

    void MethodToUpdateGui(TaskScheduler uiScheduler)
    {
        var updateTask = Task.Factory.StartNew( () =>
        {
            // update gui
        }, CancellationToken.None, TaskCreationOptions.None, uiScheduler);
    
        // Block until Task completes...
        updateTask.Wait();
    }
    

    This is better than trying to spin, as it will block and get notified by the TPL automatically.

    This is effectively doing Control.Invoke instead of Control.BeginInvoke, in Windows Forms terminology.

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

Sidebar

Related Questions

Background: I have a JScript that runs when the computer starts up (from task
I have a BackgroundWorker that runs a lengthy and semi-complex task. In this BackgroundWorker,
All, I have a long running process that I run on a background thread
We have a HPC node that runs some of our tasks in it. I
I have a AsyncTask that runs and does its job and completes. onPostExecute does
I have a scheduled task that runs a script on a regular basis (every
I have a long running rake task that is gobbling up all my system
I am using MSBuild and have a Delete task that deletes all the files
I have a working SSIS task that executes once in a month and runs
I know zero javascript, and have one simple task: Find all text in the

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.