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);
            }
        }
예제 #2
0
        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();
            }));

            foreach (DirectoryInfo item in diri)
            {
                if ((sender as BackgroundWorker).CancellationPending)
                {
                    break;
                }
                FolderSizeInfoClass fsi = new FolderSizeInfoClass();
                fsi.FolderSizeLoc = item.Name;
                shol.Clear();
                long retsize = 0;
                //try
                //{
                //    GetFilesRec(ShellObject.FromParsingName(item.FullName));

                //    foreach (ShellObject item2 in shol)
                //    {
                //        if ((sender as BackgroundWorker).CancellationPending)
                //        {
                //            break;
                //        }
                //        object oo = item2.Properties.System.Size.ValueAsObject;
                //        retsize += Convert.ToInt64(oo);
                //        GC.Collect();
                //    }
                //    //ShellObject o = ShellObject.FromParsingName(dir);
                //}
                //catch (Exception)
                //{


                //}
                int ii  = 0;
                int iff = 0;
                retsize   = RecurseDirectory(item.FullName, -1, out ii, out iff);
                fsi.FSize = retsize;
                FSI.Add(fsi);
                (sender as BackgroundWorker).ReportProgress(i++);
            }
            shol.Clear();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                WindowsAPI.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
            }
        }
        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();
                                }));

            foreach (DirectoryInfo item in diri)
            {
                
                if ((sender as BackgroundWorker).CancellationPending)
                {
                    break;
                }
                FolderSizeInfoClass fsi = new FolderSizeInfoClass();
                fsi.FolderSizeLoc = item.Name;
                shol.Clear();
                long retsize = 0;
                //try
                //{
                //    GetFilesRec(ShellObject.FromParsingName(item.FullName));
                   
                //    foreach (ShellObject item2 in shol)
                //    {
                //        if ((sender as BackgroundWorker).CancellationPending)
                //        {
                //            break;
                //        }
                //        object oo = item2.Properties.System.Size.ValueAsObject;
                //        retsize += Convert.ToInt64(oo);
                //        GC.Collect();
                //    }
                //    //ShellObject o = ShellObject.FromParsingName(dir);
                //}
                //catch (Exception)
                //{


                //}
                int ii = 0;
                int iff = 0;
                retsize = RecurseDirectory(item.FullName, -1, out ii, out iff);
                fsi.FSize = retsize;
                FSI.Add(fsi);
                (sender as BackgroundWorker).ReportProgress(i++);

                
                
            }
            shol.Clear();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                WindowsAPI.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
            }
        }
        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);
            }
        }