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