Just a quick query... one of my C# programs keeps freezing when the following code goes into the catch statement. I'm basically wondering what is the best method of writing the below code so that if it fails the program won't crash...
Cheers all!
Code:
void updateme(object sender, EventArgs e)
{
String URLString = "http://www.routehiker.org.uk/api/help/exeinterface.php?update&userid=" + settings.Default.userid;
try
{
XmlTextReader reader = new XmlTextReader(URLString);
string[] userdetails;
userdetails = new string[7];
int i = 0;
while ((reader.Read() && i < 7))
{
switch (reader.NodeType)
{
case XmlNodeType.Text:
if (reader.Value != "0")
{
userdetails[i] = reader.Value;
i++;
}
else
{
i = 7;
}
break;
}
}
if (userdetails[0] != null)
{
update.Stop();
this.Show();
MessageBox.Show(userdetails[1] + " " + userdetails[2] + " has started a conversation");
listbox_details.Items.Add("A conversation has started with " + userdetails[1] + " " + userdetails[2] + ".");
Form Other = new messenger(userdetails);
Other.ShowDialog();
listbox_details.Items.Add("The conversation with " + userdetails[1] + " " + userdetails[2] + " has ended.");
update.Start();
}
return;
}
catch { MessageBox.Show("CATCH 4"); }
}
Cheers all!