Go Back

Web Site Monitoring

Lately I have been looking at web site monitoring services and software around the web and decided why pay when I can create a windows application.

I choose to program this application in C#. So far the main elements of the application is three text boxs for entering the web site name, a box to see the response from the server, and a box to list the time the request was sent. One command button and timer for starting and stopping the monitoring service.

It has been a while since I worked with a timer object, back in my C++ days. The first thing I did was to look up the properties of the timer to determine how to stop and reset the timer with a command button, which led to the code below. To stop the timer you set the property Enabled to false, and true to start again.

private void btnTimeStopStart_Click(object sender, EventArgs e)
{
if (btnTimeStopStart.Text == "Stop")
{
btnTimeStopStart.Text = "Start";
timer1.Enabled = false;
}
else
{
btnTimeStopStart.Text = "Stop";
timer1.Enabled = true;
}
}

Next property to set was the timer interval. This interval determines when an event fires the timer1_Tick method. Values for the interval which can be set in the form view: 1000 = 1 sec, 60000 = 1 min, and 600000 = 10 mins. I choose to set my timer to 10 mins.

private void timer1_Tick(object sender, EventArgs e)
{
if (counter >= 10)
{
//Exit loop code
timer1.Enabled = false;
counter = 0;
}
else
{

txtTime.Text += DateTime.Now.ToString() + Environment.NewLine;
//Call
GetWebPage();
lblStatus.Text = "Request received at " + DateTime.Now.ToString();
//increment counter
counter = counter + 1;
}

}

The code presented in session just covers the timer function of the web monitoring application.

  • Facebook
  • Twitter
  • DZone It!
  • Digg It!
  • StumbleUpon
  • Technorati
  • Del.icio.us
  • NewsVine
  • Reddit
  • Blinklist
  • Add diigo bookmark
Post a comment!
  1. Formatting options