private void bgw_DoWork(object sender, DoWorkEventArgs e)
{
//FSI = FolderSizeInfoClass.ConstructData(e.Argument.ToString());
//List<FolderSizeInfoClass> FolderInfoSize = new List<FolderSizeInfoClass>();
DirectoryInfo data = new DirectoryInfo(e.Argument.ToString());
int i = 0;
DirectoryInfo[] diri = data.GetDirectories();
//GetAllDirRec(ShellObject.FromParsingName(data.FullName));
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
(Action)(() =>
{
progressBar1.Maximum = diri.Count();
}));
Parallel.ForEach(diri, (item, state) =>
{
if ((sender as BackgroundWorker).CancellationPending)
{
state.Break();
}
FolderSizeInfoClass fsi = new FolderSizeInfoClass();
fsi.FolderSizeLoc = item.Name;
shol.Clear();
long retsize = 0;
int ii = 0;
int iff = 0;
try
{
retsize = RecurseDirectory(item.FullName, -1, out ii, out iff);
}
catch (Exception)
{
}
fsi.FSize = retsize;
FSI.Add(fsi);
(sender as BackgroundWorker).ReportProgress(i++);
});
shol.Clear();
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
BExplorer.Shell.Interop.Shell32.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}