File tree Expand file tree Collapse file tree
src/WPFDevelopers.Shared/Core/Helpers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using Microsoft . Win32 ;
22using System ;
3+ using System . Diagnostics ;
34using System . IO ;
45using System . Reflection ;
56using System . Security . Cryptography ;
67using System . Text . RegularExpressions ;
8+ using System . Threading ;
79using System . Windows ;
810using 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 ;
You can’t perform that action at this time.
0 commit comments