I have written this working code to fire the window service at every 3 seconds interval but unable to implement for the specific system time like 12:30 AM. This code is working fine but i need the idea to implement with specific system time. Please Guide me .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
namespace WindowsServiceForOnlineMockTest
{
public partial class Service1 : ServiceBase
{
System.Timers.Timer sysTimer = new System.Timers.Timer();
private int _interval = 3000;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
sysTimer.Interval = _interval;
sysTimer.Enabled = true;
sysTimer.Start();
sysTimer.Elapsed += new System.Timers.ElapsedEventHandler(onElapsed);
}
protected override void OnStop()
{
}
private void onElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
try
{
SqlCommand cmd = new SqlCommand("changeid", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
EventLog.WriteEntry("Error", ex.Message, EventLogEntryType.Warning);
}
}
}
}