You can use a static Timer and start it from the Application_Start()
method in Global.asax
.
Within Global.asax
, add the following field:
static Timer _timer = null;
Then you can make your Application_Start()
like:
void Application_Start(object sender, EventArgs e)
{
if (_timer == null)
{
_timer = new Timer();
_timer.Interval = 1000; // some interval
_timer.Elapsed += new ElapsedEventHandler;
_timer.Start();
}
}
void ElapsedEventHandler(object sender, ElapsedEventArgs e)
{
string filePath = "/files/myfile.txt";
if (Directory.Exists(filePath))
{
other_tasks_operations();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…