How to Prevent 'UI Freeze by using .GetFiles in WPF' : <p>This is a fuction that compare the contents of two folders.</p>

<p>Issue:</p>

<p>When using System.IO.DirectoryInfo.GetFiles() the application is freezing (15 
sec), I know that's because it's using the main thread... it's 10 GB.</p>

<p>The reason why I'm not using a thread, sync or whatever is because I need the 
"fileInfosToCopy" list in by main thread, so when I'm going to use a thread I 
can not access it anymore.</p>

<p>Any ideas? I only need the "fileInfosToCopy" list in my main thread.</p>

<pre><code>string pathA = @"\\server\share\folder";
string pathB = @"C:\folder";


public void Scan()
    {
        try
        {
            string Computer = "server";
            Ping ping = new Ping();
            PingReply reply = ping.Send(Computer);

            if (reply.Status == IPStatus.Success)
            {

                var netwerkfolder = new DirectoryInfo(pathA);
                var localfolder = new DirectoryInfo(pathB);

                var networkfiles = netwerkfolder.GetFiles("*.*", SearchOption.AllDirectories);
                var localfiles = localfolder.GetFiles("*.*", SearchOption.AllDirectories);

                var listmissingfiles = networkfiles.Select(s =&gt; s.Name).ToList().Except(localfiles.Select(s =&gt; s.Name)).ToList();

                var fileInfosToCopy = new List&lt;FileInfo&gt;();

                foreach (var info in networkfiles)
                {
                    if (listmissingfiles.Contains(info.Name))
                    {
                        fileInfosToCopy.Add(info);

                    }
                }
            }
            else
            {
              // not connected
            }
        }
        catch (Exception)
        {
          // x
        }
    }
}
</code></pre>
