G
GT
Hello,
Problem with catching exceptions in WebClient.UploadFileAsync.
VS 2005 winform project using WebClient.UploadFileAsync. Everything works
fine so far (with Progressbar + Credentials) but when an error occurs
(Server not reachable, Connection broken...) the exception is not caught, it
ends up with "Exception has been thrown by the target of an invocation" in
main(). When WebClient.UploadFile is used, evreything works fine.
WebClient wc = new WebClient();
wc.UploadFileCompleted += new
UploadFileCompletedEventHandler(UploadFileCallback);
wc.UploadProgressChanged += new
UploadProgressChangedEventHandler(UploadProgressCallback);
wc.Credentials = new NetworkCredential(uid, pw, "");
Uri uri = new Uri("http://server/file_receive.aspx");
try
{
wc.UploadFileAsync(uri, "POST", path2file);
}
catch (WebException wex)
{
throw (wex);
}
catch (Exception ex)
{
throw (ex);
}
Thanks a lot
Problem with catching exceptions in WebClient.UploadFileAsync.
VS 2005 winform project using WebClient.UploadFileAsync. Everything works
fine so far (with Progressbar + Credentials) but when an error occurs
(Server not reachable, Connection broken...) the exception is not caught, it
ends up with "Exception has been thrown by the target of an invocation" in
main(). When WebClient.UploadFile is used, evreything works fine.
WebClient wc = new WebClient();
wc.UploadFileCompleted += new
UploadFileCompletedEventHandler(UploadFileCallback);
wc.UploadProgressChanged += new
UploadProgressChangedEventHandler(UploadProgressCallback);
wc.Credentials = new NetworkCredential(uid, pw, "");
Uri uri = new Uri("http://server/file_receive.aspx");
try
{
wc.UploadFileAsync(uri, "POST", path2file);
}
catch (WebException wex)
{
throw (wex);
}
catch (Exception ex)
{
throw (ex);
}
Thanks a lot