using System;
using System.Collections.Generic;
using System.Text;
namespace AgileConfig.Server.Common
{
public class FunctionUtil
{
///
/// 尝试运行一个Func几次
///
///
///
///
///
public static T TRY(Func func, int tryCount)
{
if (func == null)
{
throw new ArgumentNullException("func");
}
T result = default(T);
for (int i = 0; i < tryCount; i++)
{
try
{
result = func();
break;
}
catch (Exception ex)
{
if (i == (tryCount - 1))
{
throw ex;
}
}
}
return result;
}
///
/// 尝试运行一个Action几次
///
///
///
///
///
public static void TRY(Action act, int tryCount)
{
if (act == null)
{
throw new ArgumentNullException("act");
}
for (int i = 0; i < tryCount; i++)
{
try
{
act();
break;
}
catch (Exception ex)
{
if (i == (tryCount - 1))
{
throw ex;
}
}
}
}
}
}