Answer the question
In order to leave comments, you need to log in
How to update ProgressBar in c# side thread?
Sorry, the topic is beaten, but I do not understand what needs to be done.
I start the thread:
private void button3_Click(object sender, EventArgs e)
{
ProgressBar.Maximum = listToCalc.Count;
ProgressBar.Value = 0;
ProgressBar.Step = 1;
listOfWells.Clear();
thread = new Thread(calc);
thread.Start();
}
public void calc()
{
for (int i = 0; i < listToCalc.Count; i++) {
listOfWells.Add(new Well(listToCalc[i]));
listOfWells[i].calcP();
ProgressBar.PerformStep(); - Выскакивает исключение!
}
}
Answer the question
In order to leave comments, you need to log in
this.Invoke((MethodInvoker) delegate() {
ProgressBar.PerformStep();
});
this.Invoke
(remember this) to be called on the UI thread, and MethodInvoker is simply type casting. this.Invoke((MethodInvoker) (() =>
{
ProgressBar.PerformStep();
}));
this.Invoke((MethodInvoker) () =>
{
ProgressBar.PerformStep();
});
0.5
, "abc"
or new Button()
) is the following:() =>
{
ProgressBar.PerformStep();
}
MethodInvoker
, why then these brackets around the value, we don’t write int x = (int)(0.5);
, alas, when casting types, it’s not always possible to limit yourself to parentheses only for the type and omit them for the value being cast, of course you can forget about this and it won’t compile, but with experience you already know, if the cast does not compile, then you need to try adding parentheses for the value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question