Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么在与backgroundworker it报告进度时';她从来没有参加过这个活动吗?_C#_.net_Winforms - Fatal编程技术网

C# 为什么在与backgroundworker it报告进度时';她从来没有参加过这个活动吗?

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。是否已

在FindLines方法中,我在两个地方使用了reportprogress:

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);