Application freezes when trying to read Author from .doc multiple files

I'm trying to make an app that displays all authors of .doc files from a Folder and its subfolders, the problem is that I used Directory.GetFiles("*.doc", SearchOption.AllDirectories) and when I'm trying to read from a folder with very much files, the app freeze in this point. Here is my code

FileInfo[] Files = dir.GetFiles("*.doc", SearchOption.AllDirectories);
foreach(FileInfo file in Files) 
{
    try
    {
        //ConvertDOCToDOCX(file.FullName);
        using(WordprocessingDocument sourcePresentationDocument = WordprocessingDocument.Open(file.FullName, false)) 
        {
            metadataList.Add(new Metadata() 
            {
                Name = "Title", Value = file.Name
            });
            metadataList.Add(new Metadata() 
            {
                Name = "Author", Value = sourcePresentationDocument.PackageProperties.Creator
            });
            metadataList.Add(new Metadata() 
            {
                Name = "", Value = ""
            });
        }
    }
}
Jon Skeet
people
quotationmark

the app freeze in this point

Yes, because you're doing a lot of work in the UI thread. Don't do that - never do that.

You should probably do all that work in a background thread (either with BackgroundWorker or maybe Task.Run) and then only modify the UI (on the UI thread) when you're done.

people

See more on this question at Stackoverflow