This is a fuction that compare the contents of two folders.
Issue:
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.
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.
Any ideas? I only need the "fileInfosToCopy" list in my main thread.
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 => s.Name).ToList().Except(localfiles.Select(s => s.Name)).ToList();
var fileInfosToCopy = new List<FileInfo>();
foreach (var info in networkfiles)
{
if (listmissingfiles.Contains(info.Name))
{
fileInfosToCopy.Add(info);
}
}
}
else
{
// not connected
}
}
catch (Exception)
{
// x
}
}
}