Why when using backgroundworker to read files from hard disk sometimes the program freeze hold?

318 Views Asked by At

I think the reason is that it's reading/loading each file from the hard disk some files size are 8.5MB I'm using OpenPop to load eml(emails) files i downloaded and saved from my pop3 email provider.

Now on the hard disk i have over 7000 eml files some 8.5MB some 23KB

int countUploadMsg = 0;
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            int counter = 0;
            allLoadedMessages = new List<OpenPop.Mime.Message>();
            OpenPop.Mime.Message loadedMessage = null;
            DirectoryInfo di = new DirectoryInfo(@"e:\testmail\");
            FileInfo[] files = di.GetFiles();
            foreach (FileInfo file in files)
            {
                loadedMessage = OpenPop.Mime.Message.Load(file);
                allLoadedMessages.Add(loadedMessage);
                counter += 1;
                int nProgress = counter * 100 / files.Length;
                backgroundWorker2.ReportProgress(nProgress);
            }
        }

For sure the problem is with this line:

loadedMessage = OpenPop.Mime.Message.Load(file);

With the Load part of the OpenPop library.

So maybe it's taking time it's not that fast i tried but i didn't find so far a faster eml files reader/parser.

My question is why if the code is inside the DoWork event of the backgroundworker sometimes the program stop/freeze for few seconds on some files ? Isn't it should work smooth using backgroundworker ? Maybe longer time but why the program freeze sometimes ? I'm using backgroundworker for the Load but it seems that sometimes it's reading the files from the hard disk and make the program freeze until it's finishing reading the current file it is on.

1

There are 1 best solutions below

0
On

If the problem is that OpenPOP's MIME parser is slow (and it is according to my own benchmarks), you could try switching to my MimeKit library which is significantly faster (i.e. more than 25x faster) than OpenPOP.