コード例 #1
0
        private static void SearchDirectory(DirectoryInfo dirInfo)
        {
            if (!_cancellationTokenSource.IsCancellationRequested)
            {
                while (_pauseSearch)
                {
                    // стоит на паузе
                }

                try
                {
                    foreach (var info in dirInfo.GetFileSystemInfos(_searchParams.FileName))
                    {
                        _count++;
                        SearchInfo?.Invoke(new SearchInfoEventArgs(info, _count));

                        if (_cancellationTokenSource.IsCancellationRequested)
                        {
                            break;
                        }

                        while (_pauseSearch)
                        {
                            // стоит на паузе
                        }

                        if (MatchesRestrictions(info))
                        {
                            _foundedCount++;

                            FoundInfo?.Invoke(new FoundInfoEventArgs(info, _foundedCount));
                        }
                    }

                    if (_searchParams.IncludeSubDirsChecked)
                    {
                        foreach (var subDirInfo in dirInfo.GetDirectories())
                        {
                            if (_cancellationTokenSource.IsCancellationRequested)
                            {
                                break;
                            }

                            while (_pauseSearch)
                            {
                                // стоит на паузе
                            }

                            SearchDirectory(subDirInfo);
                        }
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }
コード例 #2
0
        private static void SearchDirectory(DirectoryInfo dirInfo)
        {
            if (!stop)
            {
                try
                {
                    foreach (String fileName in fileName)
                    {
                        FileSystemInfo[] infos = dirInfo.GetFileSystemInfos(fileName);

                        foreach (FileSystemInfo info in infos)
                        {
                            if (stop)
                            {
                                break;
                            }
                            if (IsMatchingRestrictions(info))
                            {
                                // We have found a matching FileSystemInfo, so let's raise an event:
                                FoundInfo?.Invoke(new FileFoundInfoEventArgs(info));
                            }
                        }
                    }

                    if (includeSubDirsChecked)
                    {
                        DirectoryInfo[] subDirInfos = dirInfo.GetDirectories();
                        foreach (DirectoryInfo subDirInfo in subDirInfos)
                        {
                            if (stop)
                            {
                                break;
                            }

                            // Recursion:
                            new Thread(() => { SearchDirectory(subDirInfo); }).Start();
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }