mirror of https://github.com/SixLabors/ImageSharp
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.
52 lines
2.0 KiB
52 lines
2.0 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="TaskHelpers.cs" company="James South">
|
|
// Copyright (c) James South.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace ImageProcessor.Web.Helpers
|
|
{
|
|
#region Using
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Provides some syntactic sugar to run tasks.
|
|
/// </summary>
|
|
public sealed class TaskHelpers
|
|
{
|
|
/// <summary>
|
|
/// Queues the specified work to run on the ThreadPool and returns a Task handle for that work.
|
|
/// </summary>
|
|
/// <param name="action">The work to execute asynchronously</param>
|
|
/// <returns>A Task that represents the work queued to execute in the ThreadPool.</returns>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// The <paramref name="action"/> parameter was null.
|
|
/// </exception>
|
|
public static Task Run(Action action)
|
|
{
|
|
Task task = new Task(action);
|
|
task.Start();
|
|
return task;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Queues the specified work to run on the ThreadPool and returns a proxy for the
|
|
/// Task(TResult) returned by <paramref name="function"/>.
|
|
/// </summary>
|
|
/// <typeparam name="TResult">The type of the result returned by the proxy Task.</typeparam>
|
|
/// <param name="function">The work to execute asynchronously</param>
|
|
/// <returns>A Task(TResult) that represents a proxy for the Task(TResult) returned by <paramref name="function"/>.</returns>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// The <paramref name="function"/> parameter was null.
|
|
/// </exception>
|
|
public static Task<TResult> Run<TResult>(Func<TResult> function)
|
|
{
|
|
Task<TResult> task = new Task<TResult>(function);
|
|
task.Start();
|
|
return task;
|
|
}
|
|
}
|
|
}
|
|
|