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.
Zero/ZeroLevel/Services/Extensions/TaskExtension.cs

36 lines
877 B

using System;
using System.Threading.Tasks;
namespace ZeroLevel.Services.Extensions
{
public static class TaskExtension
{
public static T WaitResult<T>(this Task<T> task)
{
if (task == null)
{
throw new ArgumentNullException(nameof(task));
}
task.Wait();
if (task.IsFaulted)
{
if (task.Exception != null) throw task.Exception;
}
return task.Result;
}
public static void WaitWithoutResult(this Task task)
{
if (task == null)
{
throw new ArgumentNullException(nameof(task));
}
task.Wait();
if (task.IsFaulted)
{
if (task.Exception != null) throw task.Exception;
}
}
}
}

Powered by TurnKey Linux.