Лучшим вариантом является наличие таймера System.Timers.Timer
в вашем сервисе.
System.Timers.Timer timer = new System.Timers.Timer();
В конструкторе добавить обработчик для Elapsed
события:
timer.Interval = 1000; //miliseconds
timer.Elapsed += TimerTicked;
timer.AutoReset = true;
timer.Enabled = true;
Затем в методе OnStart
начать этот таймер:
timer.Start();
В обработчике событий делать свою работу:
private static void TimerTicked(Object source, ElapsedEventArgs e)
{
if (!File.Exists(@"C:\Users\john\logOn\oauth_url.txt"))
return;
//If the file exists do stuff, otherwise the timer will tick after another second.
}
класс минимальный сервис будет выглядеть примерно так:
public class FileCheckServivce : System.ServiceProcess.ServiceBase
{
System.Timers.Timer timer = new System.Timers.Timer(1000);
public FileCheckServivce()
{
timer.Elapsed += TimerTicked;
timer.AutoReset = true;
timer.Enabled = true;
}
protected override void OnStart(string[] args)
{
timer.Start();
}
private static void TimerTicked(Object source, ElapsedEventArgs e)
{
if (!File.Exists(@"C:\Users\john\logOn\oauth_url.txt"))
return;
//If the file exists do stuff, otherwise the timer will tick after another second.
}
}
Не делать это в OnStart. И не используйте \\, разделитель \ –