C# 为什么在与backgroundworker it报告进度时';她从来没有参加过这个活动吗?
在FindLines方法中,我在两个地方使用了reportprogress:C# 为什么在与backgroundworker it报告进度时';她从来没有参加过这个活动吗?,c#,.net,winforms,C#,.net,Winforms,在FindLines方法中,我在两个地方使用了reportprogress: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { FindLines(@"d:\c-sharp", "FileShellExtension"); } 但这永远不会成为一件大事。 我已在设计器中签入属性:WorkerReportsProgress设置为true。是否已
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
FindLines(@"d:\c-sharp", "FileShellExtension");
}
但这永远不会成为一件大事。
我已在设计器中签入属性:WorkerReportsProgress设置为true。是否已将事件处理程序附加到后台工作程序?代码在哪里?@ChrisDunaway它在设计器中附加了所有3个事件。我现在也检查了一下,看到这一行:backgroundWorker1.ReportProgress(count,“Counting Files”);整个CountFiles在一秒钟后很快完成,然后在下一行中l。Count为0。在我搜索d:\c-sharp的目录中,我有很多目录、子目录和文件。CountFiles和backgroundWorker1有问题。ReportProgress(count,“Counting files”);我刚刚测试并在方法FindLines的顶部添加了一行:backgroundWorker1.ReportProgress(0);它到达progresschanged事件。您是否已将事件处理程序附加到后台工作程序?代码在哪里?@ChrisDunaway它在设计器中附加了所有3个事件。我现在也检查了一下,看到这一行:backgroundWorker1.ReportProgress(count,“Counting Files”);整个CountFiles在一秒钟后很快完成,然后在下一行中l。Count为0。在我搜索d:\c-sharp的目录中,我有很多目录、子目录和文件。CountFiles和backgroundWorker1有问题。ReportProgress(count,“Counting files”);我刚刚测试并在方法FindLines的顶部添加了一行:backgroundWorker1.ReportProgress(0);这件事发生了变化。
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
FindLines(@"d:\c-sharp", "FileShellExtension");
}
CountFiles(di, l, count =>
{
backgroundWorker1.ReportProgress(count, "Counting Files");
});
int totalFiles = l.Count;
int countFiles = 0;
if (di != null && di.Exists)
{
if (CheckFileForAccess(DirName) == true)
{
foreach (FileInfo fi in l)
{
backgroundWorker1.ReportProgress((int)((double)countFiles / totalFiles * 100.0), fi.Name);