You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
893 B

namespace EC.Util.Common;
2 years ago
public class TaskUtil
2 years ago
{
public static Task Run(Action action)
2 years ago
{
return Task.Run(action);
}
/// <summary>
/// 相比于 Run,直接捕获并记录异常
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
public static Task RunCatch(Action action)
2 years ago
{
return Task.Run(() =>
{
try
{
action();
}
catch (Exception e)
{
LogUnit.Error(typeof(TaskUtil), e);
2 years ago
}
});
}
2 years ago
/// <summary>
/// 相比于 Run,能及时抛出并全局捕获异常
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
public static Task LongRun(Action action)
{
return Task.Factory.StartNew(action, TaskCreationOptions.LongRunning);
}
2 years ago
}