Hi I have a timer so that when it goes off it will access the database however it doesn't appear to be working. I've never used timers before so not sure if I've written it correctly. The code for the timer is:
public void timer_method()
{
int heartbeat = Convert.ToInt32(textBox1.Text);
int ms = heartbeat * 1000;
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(onTimerEvent);
aTimer.Interval = ms;
aTimer.Start();
}
private void onTimerEvent(object sender, System.Timers.ElapsedEventArgs e)
{
//throw new NotImplementedException();
String svcGuid = "e43a8a14-be7f-4367-8420-0fd0f6273bf0";
Guid gu = new Guid(svcGuid);
SqlCommand sql = new SqlCommand("sp_idle");
sql.CommandType = CommandType.StoredProcedure;
sql.Connection = conn;
sql.Parameters.AddWithValue("@id", gu);
sql.Parameters.Add(new SqlParameter()
{
ParameterName = "RETURN_VALUE",
Direction = ParameterDirection.ReturnValue
});
if (conn.State != ConnectionState.Open)
{
conn.Open();
sql.ExecuteNonQuery();
}
MessageBox.Show("test");
}
At the minute when I run the code the message box appears every x seconds however the stored procedure doesn't run. Thanks in advance.