Q:

Sleep until file exists/created

for reference I have looked at 
Is there a way to check if a file is in use?
and How to wait until File.Exists?
but I want to avoid using SystemWatcher as it seems kind of overdoing. My application is calling cmd prompt to create a file and as there is no ways for my application to know when it is finished I was thinking of using Sleep() as long as the file does not exist.
string filename = @"PathToFile\file.exe";
int counter = 0;
while(!File.Exists(filename))
{
    System.Threading.Thread.Sleep(1000);
    if(++counter == 60000)
    {
        Logger("Application timeout; app_boxed could not be created; try again");
        System.Environment.Exit(0);
    }
}

Somehow this code of mine does not seem to work. What could be the cause?

A:

Not sure what part isn't working. Did you realize that your loop will run for 60,000 seconds (16.67 hours)? You are incrementing it once per second and waiting for it to reach 60000.
Try something like this:
const string filename = @"D:\Public\Temp\temp.txt";

// Set timeout to the time you want to quit (one minute from now)
var timeout = DateTime.Now.Add(TimeSpan.FromMinutes(1));

while (!File.Exists(filename))
{
    if (DateTime.Now > timeout)
    {
        Logger("Application timeout; app_boxed could not be created; try again");
        Environment.Exit(0);
    }

    Thread.Sleep(TimeSpan.FromSeconds(1));
}

