hi all...i have a web service with a timer which has an Elapsed time of 1second(code should get executed for every second).....wit h the following code.....its running perfectly for the first time and has a problem during the next second...the code under "onelapsedt ime" is getting executed.....
public partial class Service1 : ServiceBase
{
Timer timer1 = new Timer();
SqlConnection cn = new SqlConnection(" Server=localhos t;Database=xyz; Integrated Security=false; User Id=x;Password=y ;");
SqlConnection cn1 = new SqlConnection(" Server=localhos t;Database=xyz; Integrated Security=false; User Id=x;Password=y ;");
public Service1()
{
InitializeCompo nent();
}
protected override void OnStart(string[] args)
{
this.timer1.Ena bled = true;
this.Call_Me();
timer1.Elapsed += new ElapsedEventHan dler(OnElapsedT ime);
timer1.Interval = 1000;
timer1.Enabled = true;
}
protected override void OnStop()
{
this.timer1.Ena bled = false;
}
private void Call_Me()
{
SqlCommand command = null;
SqlDataReader reader = null;
string curdate = TimeZone.Curren tTimeZone.ToUni versalTime(Date Time.Now).AddHo urs(-5).ToString();
try
{
cn.Open();
command = new SqlCommand("sel ect p.project_id,n. entered_date,n. record_id,n.not e_id from project AS p INNER JOIN notes as n on p.project_id=n. project_id where p.status_id=10 and n.note_id in(select max(note_id) from notes group by project_id) order by 1", cn);
reader = command.Execute Reader();
while (reader.Read())
{
TimeSpan span = Convert.ToDateT ime(curdate).Su btract(Convert. ToDateTime(read er[1]));
//code to send emails exactly after 2days..
if (span.Days * 24 * 60 * 60 + span.Hours * 60 * 60 + span.Minutes * 60 + span.Seconds >= 172800 && reader[2].ToString() == "")
{
Sending_Mails(C onvert.ToInt32( reader[0]));
Status_Change(1 , Convert.ToInt32 (reader[3]));
}
else if (span.Days * 24 * 60 * 60 + span.Hours * 60 * 60 + span.Minutes * 60 + span.Seconds >= 259200 && reader[2].ToString() == "1")
{
//code to automatically change the ticket status after 3days..
command = new SqlCommand("upd ate project set completed_date ='" + Convert.ToDateT ime(curdate) + "' ,status_id=6 where project_id='" + reader[0] + "'", cn1);
cn1.Open();
command.Execute NonQuery();
cn1.Close();
Status_Change(2 , Convert.ToInt32 (reader[3]));
}
}
reader.Close();
}
catch (Exception ex)
{
System.Diagnost ics.Debug.Write Line(ex.Message );
}
finally
{
command.Dispose ();
cn.Dispose();
}
}
private void OnElapsedTime(o bject source, ElapsedEventArg s e)
{
this.Call_Me();
}
private void Sending_Mails(i nt project_id)
{
some code here...
}
private void Status_Change(i nt i,int j)
{
some code here...
}
Can anyone help me out.......any help wud be appreciated....