First Create a windows service by following steps
[
^]
write following code in service1.cs file
protected override void OnStart(string[] args)
{
try
{
int iHourIn24HourFormat = Convert.ToInt32(DateTime.Now.ToString("HH"));
int iCurrentMinutes = DateTime.Now.Minute;
int iCurrentSecond = DateTime.Now.Second;
int iFirstIntervalGapInHours = 24 - iHourIn24HourFormat;
eventLog1.WriteEntry("Service Started ---->" + DateTime.Now.ToString());
objTimer.Interval = (1000 * 60 * 60 * iFirstIntervalGapInHours) + (1000 * 60 * 60 * 2) - (1000 * 60 * iCurrentMinutes) - (1000 * iCurrentSecond);
eventLog1.WriteEntry("Interval -> " + objTimer.Interval.ToString());
objTimer.Enabled = true;
objTimer.Elapsed += new ElapsedEventHandler(objTimer_Elapsed);
objTimer.Start();
}
catch (Exception ex)
{
eventLog1.WriteEntry("Error: " + ex.Message);
}
}
void objTimer_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
eventLog1.WriteEntry("Timer Elapsed ---->" + DateTime.Now.ToString());
objTimer.Interval = 1000 * 60 * 60 * 24;
ContinueProcess();
}
catch (Exception ex)
{
eventLog1.WriteEntry("Error: " + ex.Message);
}
}
private void ContinueProcess()
{
HttpWebRequest objHttpWebRequest;
HttpWebResponse objHttpWebResponse = null;
try
{
objHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.xyz.com/email_Service.aspx");
objHttpWebRequest.Timeout = 300000;
objHttpWebRequest.Proxy = null;
objHttpWebRequest.Method = "Get";
objHttpWebRequest.ContentLength = 0;
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
Stream objResponseStream = objHttpWebResponse.GetResponseStream();
}
catch (Exception ex)
{
eventLog1.WriteEntry("ContinueProcess Error: " + ex.Message);
}
finally
{
if (objHttpWebResponse != null)
{
objHttpWebResponse.Close();
}
objHttpWebRequest = null;
objHttpWebResponse = null;
}
}
In your email_Service.aspx page write following code in page_load event
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}