// -----------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
// -----------------------------------------------------------------------
namespace ImageProcessor.Web.Helpers
{
#region Using
using System;
using System.Threading.Tasks;
#endregion
///
/// Provides some syntactic sugar to run tasks.
///
public sealed class TaskHelpers
{
///
/// Queues the specified work to run on the ThreadPool and returns a Task handle for that work.
///
/// The work to execute asynchronously
/// A Task that represents the work queued to execute in the ThreadPool.
///
/// The parameter was null.
///
public static Task Run(Action action)
{
Task task = new Task(action);
task.Start();
return task;
}
///
/// Queues the specified work to run on the ThreadPool and returns a proxy for the
/// Task(TResult) returned by .
///
/// The type of the result returned by the proxy Task.
/// The work to execute asynchronously
/// A Task(TResult) that represents a proxy for the Task(TResult) returned by .
///
/// The parameter was null.
///
public static Task Run(Func function)
{
Task task = new Task(function);
task.Start();
return task;
}
}
}