diff --git a/source/BulkCrapUninstaller/Forms/Windows/JunkRemoveWindow.cs b/source/BulkCrapUninstaller/Forms/Windows/JunkRemoveWindow.cs index e1d1a788..5dbf8c27 100644 --- a/source/BulkCrapUninstaller/Forms/Windows/JunkRemoveWindow.cs +++ b/source/BulkCrapUninstaller/Forms/Windows/JunkRemoveWindow.cs @@ -154,7 +154,7 @@ private void CreateBackup(string backupPath) try { - FilesystemTools.CompressDirectory(dir); + FilesystemTools.CompressDirectory(dir, TimeSpan.FromMinutes(2)); } catch { diff --git a/source/KlocTools/Tools/FilesystemTools.cs b/source/KlocTools/Tools/FilesystemTools.cs index eeeaf2a3..296c0a91 100644 --- a/source/KlocTools/Tools/FilesystemTools.cs +++ b/source/KlocTools/Tools/FilesystemTools.cs @@ -108,12 +108,13 @@ public static void MoveDirectory(DirectoryInfo source, DirectoryInfo target) } } - public static void CompressDirectory(string dirFullName) + public static void CompressDirectory(string dirFullName) => CompressDirectory(dirFullName, ManagementOptions.InfiniteTimeout); + public static void CompressDirectory(string dirFullName, TimeSpan timeout) { var objPath = "Win32_Directory.Name=" + "\"" + dirFullName.Replace(@"\", @"\\") + "\""; using (var dir = new ManagementObject(objPath)) { - var outParams = dir.InvokeMethod("Compress", null, null); + var outParams = dir.InvokeMethod("Compress", null, new InvokeMethodOptions { Timeout = timeout }); if (outParams == null) throw new ArgumentNullException(nameof(outParams)); var ret = (uint)outParams.Properties["ReturnValue"].Value; if (ret != 0)