I wanted to create a service which runs automatically on everyday at 4.00 am, and that method would delete some files automatically when it is called, i have written the code but my method which i am calling in service is not getting executed. Below i have attached my code , please somebody suggest me a solution.
public partial class Scheduler : ServiceBase
{
System.Timers.Timer _timer;
public Scheduler()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
_timer = new System.Timers.Timer();
_timer.Interval = 1 * 60 * 1000;//Every one minute
_timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
_timer.Start();
}
catch (Exception ex)
{
Library.WriteErrorLog(ex);
}
}
public void timer_Elapsed(object sender, ElapsedEventArgs e)
{
Library.WriteErrorLog("Timer elapsed");
this.ExtractDataFromSharePoint();
}
public void ExtractDataFromSharePoint()
{
Library.WriteErrorLog("inside task");
ArchiveAdministration admin = new ArchiveAdministration();
admin.ArchiveAuto();
Library.WriteErrorLog("job completed");
_timer.Stop();
}
}
And my log file has only the following output statements:
Timer Elapsed
inside task
I am not getting " Job completed " statement which i have included..