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:
private void ScureExecuter(Action action)
{
if (InvokeRequired)
{
Invoke(new MethodInvoker(() => action()));
}
else
{
action();
}
}
and run as follows like:
- ScureExecuter(() => label1.Text=string.Empty);
- ScureExecuter(() => label1.Update());
- ScureExecuter(() => progressBar1.Visible = true);
- ScureExecuter(() => progressBar1.Maximum = list.Count);
- ScureExecuter(() => progressBar1.Step = 1);
No comments: