I currently have a while loop, which contains an if statement:
if (s.Contains("mp4:production/CATCHUP/"))
Although when this condition is true, and I try to use other methods (as seen below e.g. RemoveEXELog) I get an access denied a process is currently using the file “Command.bat”.
How could I stop looping the file when I execute my other methods?
private void CheckLog()
{
while (true)
{
Thread.Sleep(5000);
if (!System.IO.File.Exists("Command.bat")) continue;
using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
if (s.Contains("mp4:production/CATCHUP/"))
{
RemoveEXELog(); // Deletes a specific keyword from Command.bat
Process p = new Process();
p.StartInfo.WorkingDirectory = "dump";
p.StartInfo.FileName = "test.exe";
p.StartInfo.Arguments = s;
p.Start();
ClearLog(); // Deletes Command.bat and then creates a new empty Command.bat
}
}
}
}
}
1 Answer