在 httprequest CLR C# 中隐藏超时错误

Hide timeout errors in httprequest CLR C#

我有代码 C# (CLR):

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://sitewait10seconds.com/script.php?param=1");
httpWebRequest.Method = "GET";
httpWebRequest.Timeout = 30;
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
httpWebRequest.Abort();
httpResponse.Close();

我在循环中调用这个 CLR,我想在调用 script.php 后关闭连接,因为我不需要任何响应,我想用下一个参数调用这个 CLR。 我设置

httpWebRequest.Timeout = 30; 

但是我得到一个错误

A .NET Framework error occurred during execution of user-defined routine or aggregate "myProcedure": 
System.Net.WebException: The operation has timed out
System.Net.WebException: 
at System.Net.HttpWebRequest.GetResponse()
at StoredProcedures.InsertCurrency_CS(.....

是否有隐藏此消息并让此代码继续运行的选项?

您可以像这样忽略特定的异常:

try
{
    // do something
}
catch (Exception ex)
{
    if (ex.Message.Contains("The operation has timed out")) return;
}