i use winrar to extract a rar file in my application. after that extract is compete i need to move the extracted file but it some times it has this error: The process cannot access the file because it is being used by another process
i guess that error is Regarding to winrar so i kill winrar process but the error exist
I use (Process.HasExited ) to force program to sleep for 5 minute i can kill process but have following problem: but The process cannot access the file because it is being used by another process and use code for kill process :
try
{
Process proc = Process.GetProcessById(id);
proc.Kill();
}
catch (Exception ex)
{
Process[] processlist = Process.GetProcesses();
foreach (Process p in Process.GetProcesses("."))
{
try
{
if (p.ProcessName.ToLower().Contains("winrar"))
{
string str = Bussiness.ClsCommandLine.GetCommandLine(p);
if (str.ToLower().Contains((fileName.ToLower()))
{
Process prc = Process.GetProcessById(p.Id);
prc.Kill();
}
}
}
catch (Exception ex1)
{
result = false;
}
}
}
any idea?