Hello!
I am building a program that keeps eye on website and notices the user if the content of the site changes. My problem is error handling... to be presice: the lack of it.
If the website that program is monitoring goes down (for example error 500) my program crashes. Otherwise it is working great. How do i add error handling that makes announcement "Site is down" incase WebClient gets error 500? Here is clip of my code (names in finnish):
public void Is_Alive()
{
bool onko;
string sisaltaa = "Third-party server not responding";
string tietoteksti = "No info";
string vahdattava = "http://www.hereisurl.com";
WebClient myWebClient = new WebClient();
byte[] bufferi = myWebClient.DownloadData(vahdattava);
string tulos = Encoding.ASCII.GetString(bufferi);
onko = tulos.Contains(sisaltaa);
if (onko == true)
{
tietoteksti = "Changes!";
SystemSounds.Exclamation.Play();
downtimelaskuri();
if (viimeksikinalhaalla==false)
{
kyykyta();
}
if (notifyIcon1.Visible == true)
{
notifyIcon1.ShowBalloonTip(30, "Wake up!", "Changes!", ToolTipIcon.Warning);
}
viimeksikinalhaalla=true;
}
else
{
tietoteksti = "It's the same.";
viimeksikinalhaalla=false;
}
label1.Text = tietoteksti;
}