且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

后台工作者和Progressbar无法正常工作

更新时间:2023-02-01 15:28:08

在您的ProgressChanged事件中,您必须使用委托来更新ProgressBar控件.

In your ProgressChanged event, you have to use a delegate to update the ProgressBar control.

public void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    MethodInvoker involker = delegate 
    { 
        tooltipProgressBar1.Value = e.ProgressPercentage; 
    };     
    tooltipProgressBar1.BeginInvoke(invoker); 
}



您也确实不需要发布所有theat源代码.它只是使您的问题变得混乱.



You really didn''t need to post all theat source code, either. It just cluttered your question.


它应该可以工作.
您是否使用调试器来确保您的工作人员启动了?您输入DoWork处理程序吗?
您的进度栏是否正常"?例如,确保进度条的范围有效.
而且我看到您正在使用toolStripProgressBar.您应该尝试使用普通的ProgressBar进行检查.

查看以下链接:
ProgressWorker [ ProgressForm:链接到BackgroundWorker的简单表单 [
It should work.
Did you use the debugger to make sure your worker starts? Do you enter the DoWork handler?
Is your progress bar "normal"? For example make sure the range of your progress bar is valid.
And I see that you are using toolStripProgressBar. You should try with a normal ProgressBar just to check.

Check out these links:
ProgressWorker[^]
ProgressForm: A simple form linked to a BackgroundWorker[^]


我拿了您的代码并将其作为示例运行.它对我来说效果很好,这使我想知道您遇到的问题是btnCompare 是否未映射到btnCompare_Click.在此方法中放置一个断点,看看是否命中它.
I took your code and ran it as a sample. It works perfectly for me, which leads me to wonder if the problem that you are having is that btnCompare isn''t mapped to btnCompare_Click. Put a breakpoint inside this method and see if it hits it.