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