我有下面的代碼從網上下載的二進制文件:WebClient.DownloadDataAsync SocketException撞毀我的應用程序
WebClient client = new WebClient();
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadDataCompleted);
client.DownloadDataAsync(uri);
一切運作良好,直到連接將被切斷。如果我禁用我的無線,應用程序崩潰了:
System::Windows::Forms::Application::ThreadException event occured
SENDER: System.Threading.Thread
EXCEPTION: System.Net.Sockets.SocketException
MESSAGE: A socket operation was attempted to an unreachable network 74.200.243.250:80
SOURCE: System
CALL STACK
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
如何捕獲這個異常,或者,因爲它是在它自己的線程,如何從崩潰我的應用程序停止嗎?
哈,這比我想象的要容易得多。 – 2010-07-16 16:08:22
但是,這裏奇怪的是,這個異常實際上正在拋出並導致應用程序崩潰。如果異常應該只在.Error屬性中生成,那麼實際上什麼時候會拋出異常並導致應用程序崩潰? – 2012-01-23 21:49:43