开发者

C# skip all proxy exceptions - time-out

Is there any way i can skip/catch all 开发者_开发百科proxy exceptions? And also maybe put a time-out so the program wont get stuck in-between

webProxy = new WebProxy("" + prox + "");
webProxy.Credentials = CredentialCache.DefaultCredentials;
wr.Proxy = webProxy;

I've added

             catch (Exception ex)
            {
                // Do nothing or log
                var exceptio = ex.ToString();
                richTextBox1.Text = exceptio;
            }

how can i put a time-out on it?


Would a try/catch block help with this?


As suggested you need to enclose the executing code in a try/catch block.
You can fiddle around with debugger Exception handling under Debug/Exceptions... (in Visual Studio) but regardless, any non-handled exception will always trigger the debugger to break.

try
{
    // Do work that might fail
}
catch (Exception ex)
{
    // Do nothing or log
    Trace.WriteLine(ex);
}

More on debugging and exceptions can be found here

Regarding time-out, you put it on the WebRequest object, not on the proxy, like so:

WebProxy webProxy = new WebProxy("http://myproxyserver:80/");
WebRequest webRequest = WebRequest.Create("http://www.stackoverflow.com");
webRequest.Proxy = webProxy;
webRequest.Timeout = 5000;  // <-- Set time out here, in milliseconds
...

Read more on timeout here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜