Sir,
I need your help.
I want to execute a function using timer at a interval of 1 hour.
Please correct this code get the function executed. Here the function:-
private void PerformTimer()
{
timer1.Start();
WebClient client = new WebClient();
string no, msg;
no = textBoxNo.Text;
msg = textBoxMSg.Text;
string baseUrl = "http://www.businesssms.co.in/sms.aspx?ID=xxxxxxx&Pwd=xxxxxxxx&PhNo=91xxxxxxxx&Text=MessageText";
Stream data = client.OpenRead(baseUrl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
timer1.Stop();
}
{
timer1.Start();
WebClient client = new WebClient();
string no, msg;
no = textBoxNo.Text;
msg = textBoxMSg.Text;
string baseUrl = "http://www.businesssms.co.in/sms.aspx?ID=xxxxxxx&Pwd=xxxxxxxx&PhNo=91xxxxxxxx&Text=MessageText";
Stream data = client.OpenRead(baseUrl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
timer1.Stop();
}
And I just called function in the onTimerEvent:-
public void OnTimerEvent(object source, EventArgs e)
{
try
{
PerformTimer();
}
catch (Exception ex)
{
MessageBox.Show(ex + "SMS02", "SMS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
{
try
{
PerformTimer();
}
catch (Exception ex)
{
MessageBox.Show(ex + "SMS02", "SMS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

Selva GanapathyPosted Mar 13, 2014, 1:35 AM
Please let me know, do you want to execute PerformTimer() method every one hour. if so you need to hook a tick event and implement you logic there or call PerformTimer() method in that event and you need to call timer1.Start(); in constructor or where ever you need to start the timer.
once the timer was starts and the tickevent (that contains the logic or PerformTimer() method) will fire with the provided interval.
Regards,
Selva Ganapathy K