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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:57:17+00:00 2026-06-11T14:57:17+00:00

I have some data, and I update it in a task: The app is

  • 0

I have some data, and I update it in a task: The app is a hack at the moment for an idea so apologies for the code.

Task.Factory.StartNew(() =>
    {
        dataGridView1.BeginInvoke((Action)(() =>
            {
                dataGridView1.SuspendLayout();
            }));

        dataSet1.Reset();
        da.Fill(dataSet1);

        dataGridView1.BeginInvoke((Action)(() =>
            {
                dataGridView1.DataSource = dataSet1.Tables[0];
                dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].Width = 50;
                dataGridView1.ResumeLayout();
            }));
    }
    ).ContinueWith(task =>
        {
            if (dataSet1.Tables[0].Rows.Count > 0)
            {
                if (lastcount != dataSet1.Tables[0].Rows.Count)
                {
                    lastcount = dataSet1.Tables[0].Rows.Count;
                    if (lastcount == 0)
                    {
                        NotifyWithMessage("The items have been cleared", "Items cleared");
                    }
                    else
                    {
                        NotifyWithMessage(String.Format("There are {0} new items in your monitor", dataSet1.Tables[0].Rows.Count));
                    }
                }
            }
        }
    );

Now, the code fundamentally works. No errors, which is nice..

When it was updated outside a task, there was no flashing of the datavgridview at all, when I run it in debug, it’s very minor and well within acceptable for the hack.. the moment I run it outside debugging… it’s terribly obvious! The suspend and resume layouts have not made any difference at all. I need the code in the thread, because the UI is lumpy responsive without – whereas it’s acceptable, but it has the bad refresh now.

My Datagridview is custom coloured depending on cell colours, but, I just cant see why there’s the difference between debug and release, I’d expect the performance the other way round!

(I tried Invoke and BeginInvoke…)

I looked at Horrible redraw performance of the DataGridView on one of my two screens

And under debug, this doesn’t flicker at all, not even a bit… Under release conditions, there is a ridiculous flicker…

What can I do?

  • 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-11T14:57:18+00:00Added an answer on June 11, 2026 at 2:57 pm

    In the end heres what I did:
    I rean the query into a new dataset, if the count was the same, then I didnt update the grid, if the count had changed I did.

    timer1.Stop();
    
            Task<Boolean>.Factory.StartNew(() =>
                {
                    DataSet t = new DataSet();
                    //_dataSet1.Reset();
                    Boolean ok = false;
                    Int16 retries = 0;
                    while (!ok && retries<3)
                    try
                    {
                        da.Fill(t);
                        ok = true;
                    }
                    catch
                    {
                        retries++;
                        Thread.Sleep(1000);
                    }
                    //if (!ok) throw new Exception("DB error");
                    if (!ok) return false;
                    try
                    {
                        if (t.Tables.Count > 0 && t.Tables[0].Rows.Count != _lastcount)
                        {
                            _dataSet1 = t;
                            _lastcount = t.Tables[0].Rows.Count;
                            return true;
                        }
                    }
                    catch {  }
                    return false;
                }).ContinueWith(task =>
                    {
                        if (task.IsFaulted)
                        {
                            SQLFailed();
                            return;
                        }
                        if (!task.Result) return;
    
    
                        Invoke((Action) (() =>
                                             {
                                                 dataGridView1.DataSource = _dataSet1.Tables[0];
                                                 dataGridView1.Columns[0].Visible = false;
                                                 dataGridView1.Columns[1].Width = 50;
                                             }));
    
                        if (_lastcount == 0)
                        {
                            NotifyWithMessage("The items have been cleared", "Items cleared");
                        }
                        else
                        {
                            NotifyWithMessage(String.Format("There are {0} new items in your monitor", _lastcount));
                        }
                    });
    
    
        timer1.Start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small app that a client uses to manually update some data.
i have ios application with xcdatamodeld, i want update some data so need a
I have a long running Async Task that sends some data to my server
I have an app in which I read some gps data and I display
In my WPF Window_Loaded event handler I have something like this: System.Threading.Tasks.Task.Factory.StartNew(() => {
I have some data loaded as a np.ndarray and need to convert it to
I have some data from log files and would like to group entries by
I have some data files in the resources/ folder for my Rubymotion project. How
I have some data which (quite reasonably) uses null and false for different meanings.
I have some data and need to create a json file with this structure

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.