C# 跳过所有代理异常 - 超时
有什么方法可以跳过/捕获所有代理异常吗? 也许还可以设置一个超时,这样程序就不会卡在中间
webProxy = new WebProxy("" + prox + "");
webProxy.Credentials = CredentialCache.DefaultCredentials;
wr.Proxy = webProxy;
我已经添加了
catch (Exception ex)
{
// Do nothing or log
var exceptio = ex.ToString();
richTextBox1.Text = exceptio;
}
如何设置一个超时?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
try/catch 块对此有帮助吗?
Would a try/catch block help with this?
正如建议的,您需要将执行代码包含在
try/catch
块中。您可以在调试/异常...(在 Visual Studio 中)下摆弄调试器异常处理,但无论如何,任何未处理的异常将始终触发调试器中断。
有关调试和异常的更多信息,请参见此处
关于超时,您将其放在
WebRequest
对象上,而不是放在代理上,如下所示:阅读有关超时的更多信息 此处。
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.
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:Read more on timeout here.