我开发一个WPF 4.0应用程序中,我们从远程Web服务获取数据。该Web服务公开各地的120多家方法给客户。如果从我的WPF应用程序的Web服务调用失败,我需要重试了N次也就是通过App.config中配置。如何实现这一点?是否有解决这个问题的任何设计模式?
解决方案 静态牛逼TryNTimes< T>(Func键< T> FUNC,诠释次)
{
而(次大于0)
{
尝试
{
返回FUNC();
}
赶上(例外五)
{
如果(--times&所述; = 0)
扔;
}
}
}
I am developing a WPF 4.0 application in which we get the data from a remote web service. The web service exposes around 120+ methods to its clients. If a web service call from my WPF application fails, I need to retry it n times which is configurable via App.Config. How to implement this? Are there any design patterns that address this problem?
解决方案static T TryNTimes<T>(Func<T> func, int times)
{
while (times>0)
{
try
{
return func();
}
catch(Exception e)
{
if (--times <= 0)
throw;
}
}
}
上一篇:反序列化到JSON字符串数组数组、字符串、序列化、JSON
下一篇:无法更新数据库&QUOT; *。MDF&QUOT;因为只读的EntityFramework数据库、QUOT、EntityFramework、MDF