Ads Top

Update UI thread from background task in c#

Copy paste this function in you project

private void ScureExecuter(Action action)
        {
            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(() => action()));
            }
            else
            {
                action();              
            }
        }

and run as follows like:


  1. ScureExecuter(() => label1.Text=string.Empty);
  2.                     ScureExecuter(() => label1.Update());
  3.                     ScureExecuter(() => progressBar1.Visible = true);
  4.                     ScureExecuter(() => progressBar1.Maximum = list.Count);
  5.                     ScureExecuter(() => progressBar1.Step = 1);


No comments:

Powered by Blogger.