2014-02-16 26 views
1

我知道該網站現在已經引起了關注,但我現在和未來應該如何處理這個案例?我應該如何處理WebException無法連接到遠程服務器?

page = client.DownloadString("http://rotter.net/scoopscache.html"); 

頁面是字符串變量。

System.Net.WebException was unhandled 
    HResult=-2146233079 
    Message=Unable to connect to the remote server 
    Source=System 
    StackTrace: 
     at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) 
     at System.Net.WebClient.DownloadString(Uri address) 
     at System.Net.WebClient.DownloadString(String address) 
     at ScrollLabelTest.Form1..ctor() in e:\scrolllabel\ScrollLabel\ScrollLabel\Form1.cs:line 41 
     at ScrollLabelTest.Program.Main() in e:\scrolllabel\ScrollLabel\ScrollLabel\Program.cs:line 18 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: System.Net.Sockets.SocketException 
     HResult=-2147467259 
     Message=A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond 199.203.52.152:80 
     Source=System 
     ErrorCode=10060 
     NativeErrorCode=10060 
     StackTrace: 
      at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 
      at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) 
     InnerException: 

回答

2

你應該把在一個try-catch-條件的請求,取決於如何重要的網頁,並顯示錯誤消息或contiunue停止程序用一個空字符串和公正的計劃我們的計劃因此

+0

Rooxo應該嘗試並抓住並嘗試在計時器中的網頁可以說每60秒或每隔幾分鐘?我的意思是一旦嘗試並捕獲構造函數,並且如果它拋出異常,然後將其移動到計時器,然後打開計時器並嘗試捕捉它,直到網頁將工作。這是一個好邏輯嗎?如果是這樣怎麼辦? – user3200169

+0

我不會一直嘗試訪問網站。如果確實需要將內容退出並出現錯誤,並讓用戶決定何時再試 – Rooxo