我想知道如何在此代码中互联网连接离线时处理异常:
private void LoginDialog_myOnLoginComplete(object sender, OnLoginEventArgs e)
{
WebClient client = new WebClient();
Uri uri = new Uri(server);
NameValueCollection parameters = new NameValueCollection();
parameters.Add("Email", e.Email);
parameters.Add("Password", e.Password);
client.UploadValuesCompleted += Client_UploadValuesCompleted;
try
{
client.UploadValuesAsync(uri, parameters);
}
catch (Exception)
{
}
}
private void Client_UploadValuesCompleted(object sender, UploadValuesCompletedEventArgs e)
{
string complete = Encoding.UTF8.GetString(e.Result);
}
当互联网连接断开时,字符串完成处理异常并且我的应用程序崩溃。我怎么能避免这种情况?