public static void RecreateDirectory(string dirPath) { if (SafeDirectory.Exists(dirPath)) { try { SafeDirectory.Delete(dirPath, true); } catch (IOException ex) { LogUtil.LogException(ex); if (SafeDirectory.EnumerateFiles(dirPath).Any()) { throw; } return; // Can't delete dir, but it is empty => skip it } } SafeDirectory.CreateDirectory(dirPath); }
public static void CleanUp() { SafeDirectory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); LogUtil.LogEvent("clean up"); try { foreach (var name in GetProcessesToKill()) { foreach (var process in Process.GetProcessesByName(name)) { LogUtil.LogEvent(string.Format("{0} process kill", name)); try { process.Kill(); process.WaitForExit(1000); // wait for exit no longer than 1 second } catch (Win32Exception) { } catch (InvalidOperationException) { } } } if (SafeDirectory.Exists(WORKING_FOLDER)) { SafeDirectory.Delete(WORKING_FOLDER, true); } } catch (Exception ex) { LogUtil.LogException(ex); // Do nothing } }