![](/img/trans.png)
[英]How can I get rid of “Out of memory” exception thrown from Visual Studio designer?
[英]How can I get the type of thrown exception from CompletedEventArgs?
我使用C#和Visual Studio 2012来开发WP8应用程序。 我为我的项目添加了一个服务引用(添加服务引用)。 所以我可以使用webservice功能。
client = new YChatWebService.WebServiceControllerPortTypeClient();
client.getDataCompleted += client_getDataCompleted;
client.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, 0, 500);
client.getDataAsync();
void client_getDataCompleted(object sender, getDataCompletedEventArgs e)
{
// e.Error.Message
}
我为getData()
设置了500ms的超时限制; 如果超过时间限制,则会出现以下错误:
“对'http://example.com/webService/index?ws=1'的HTTP请求已超出分配的超时时间。分配给此操作的时间可能是较长超时的一部分。”
这很好:)但是,我想知道抛出了什么样的异常。 像包含字符串“ TimeoutException
”的字符串变量之类的东西会很好。 我怎么能做到这一点?
你可以用
if( e.Error is TimeoutException )
查看Exception是否为TimeoutException类型
这不是来自服务器的http响应包含错误描述,而不是.net异常吗?
e.Error类是否具有“Message”以外的任何其他属性? 如果服务器也是.net,那么您可能能够匹配异常类型,但如果它不是.net则它们将不对应。
如果返回了错误代码,我只会使用它,或只搜索“超出分配的超时”文本,以确认它是超时异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.