c#progressbar工作不正常

c#progressbar工作不正常,c#,progress-bar,C#,Progress Bar,我的应用程序中有一个progressbar,它的作用等于计数器值。进度条的最大值为100,最小值为0。当程序运行时,它只会增加一个很小的百分比 while (counter < numericUpDown1.Value) { timer1.Start(); client.Send(message); counter++; timer1.Stop(); progressBar1.Value = counter; } while(计数器

我的应用程序中有一个progressbar,它的作用等于计数器值。进度条的最大值为100,最小值为0。当程序运行时,它只会增加一个很小的百分比

while (counter < numericUpDown1.Value)
{
     timer1.Start();
     client.Send(message);
     counter++;
     timer1.Stop();
     progressBar1.Value = counter;
}
while(计数器
也许您需要使用
Application.DoEvents()每次更改其值。

Fabio是正确的,如果numericdown1仅为5,则进度条将仅增加到5,因此您需要执行类似(NumberDown1.value/100)*100的操作,以获得进度条应增加的内容(在while循环之前,而不是在其内部)。然后,如果UI线程的winforms或WPF使用Dispatcher,我将创建一个委托以使用您的值更新UI线程。

您已将最大值设置为100,因此请确保计数器达到100。把这个放进去试试
progressBar1.max=(int)numericUpDown1.Value

1。您确定numericUpDown1值不等于您得到的小百分比吗?2.这可能是因为您阻塞了UI线程(但因为没有上下文,所以可能没有),这会阻止UI刷新,并使其正常工作,非常感谢