Skip to content

Commit 44e9df2

Browse files
committed
Update Helper.cs
1 parent cc7b7f3 commit 44e9df2

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • src/WPFDevelopers.Shared/Core/Helpers

src/WPFDevelopers.Shared/Core/Helpers/Helper.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Microsoft.Win32;
22
using System;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Reflection;
56
using System.Security.Cryptography;
67
using System.Text.RegularExpressions;
8+
using System.Threading;
79
using System.Windows;
810
using System.Windows.Media;
911

@@ -36,10 +38,39 @@ public static void DeleteFilesAndFolders(string targetDir)
3638
}
3739
foreach (FileInfo file in directory.GetFiles())
3840
{
41+
KillProcessUsingFile(file.FullName);
42+
Thread.Sleep(500);
3943
file.Delete();
4044
}
4145
}
4246

47+
public static bool KillProcessUsingFile(string filePath)
48+
{
49+
try
50+
{
51+
string fileName = Path.GetFileNameWithoutExtension(filePath);
52+
53+
foreach (Process process in Process.GetProcesses())
54+
{
55+
try
56+
{
57+
if (process.ProcessName.Equals(fileName, StringComparison.OrdinalIgnoreCase))
58+
{
59+
process.Kill();
60+
process.WaitForExit(5000);
61+
return true;
62+
}
63+
}
64+
catch { }
65+
}
66+
return false;
67+
}
68+
catch
69+
{
70+
return false;
71+
}
72+
}
73+
4374
static string GetCurrentDllPath()
4475
{
4576
return Assembly.GetExecutingAssembly().Location;

0 commit comments

Comments
 (0)