Nathan R

Nathan R

  • NA
  • 13
  • 15.5k

Set Timer to execute a function in c# Windows Application

Mar 13 2014 1:19 AM
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();

 
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);
}
}
 

Answers (1)