jeudi 29 octobre 2015

Is there a fast way to get all files names and paths using C#, like everything search app?

I'm trying to get all files paths and names to index them in my database for faster search in future. i have used multi-threading , and parallel class of C# but i'm couldn't get the performance i expected. there is an app named "Search Everything" , its amazing. it indexes all my files in less than 2 minutes, but my code takes longer A LOT. I checked the windows task manager and it was my hard drive limiting my code it was getting to 100% of usage. i know that's normal but how everything search did that? is there another way, maybe reading data from master file table or something? i'm confused.

here is my code :

void GetFiles(string dir)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    files.AddRange(Directory.EnumerateFiles(dir));
                    Task.Factory.StartNew(() => {
                        Parallel.ForEach(Directory.EnumerateDirectories(dir), single => {
                            GetFiles(single);
                        });
                    });
                }
                catch { }
            });
        }

Aucun commentaire:

Enregistrer un commentaire