ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Shorthand Task.Factory.FromAsync (for .NET 4.5)

This extension method series represent shorthand version of Task.Factory.FromAsync (for .NET 4.5)

Source

public static Task<TResult> ToTask<TResult>(
    this Func<TResult> function,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T, TResult>(
    this Func<T, TResult> function,
    T arg,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, TResult>(
    this Func<T1, T2, TResult> function,
    T1 arg1, T2 arg2,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, TResult>(
    this Func<T1, T2, T3, TResult> function,
    T1 arg1, T2 arg2, T3 arg3,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, TResult>(
    this Func<T1, T2, T3, T4, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, TResult>(
    this Func<T1, T2, T3, T4, T5, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task<TResult> ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(
    this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> function,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task<TResult>.Factory.FromAsync(
        function.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, callback, @object),
        function.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask(
    this Action action,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T>(
    this Action<T> action,
    T obj,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(obj, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2>(
    this Action<T1, T2> action,
    T1 arg1, T2 arg2,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3>(
    this Action<T1, T2, T3> action,
    T1 arg1, T2 arg2, T3 arg3,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4>(
    this Action<T1, T2, T3, T4> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5>(
    this Action<T1, T2, T3, T4, T5> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6>(
    this Action<T1, T2, T3, T4, T5, T6> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7>(
    this Action<T1, T2, T3, T4, T5, T6, T7> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

public static Task ToTask<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
    this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action,
    T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16,
    AsyncCallback callback = default(AsyncCallback),
    object @object = default(object),
    TaskCreationOptions creationOptions = default(TaskCreationOptions),
    TaskScheduler scheduler = default(TaskScheduler))
{
    return Task.Factory.FromAsync(
        action.BeginInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, callback, @object),
        action.EndInvoke, creationOptions,
        (scheduler ?? TaskScheduler.Current) ?? TaskScheduler.Default);
}

Example

((Func<double, double, double>)Math.Pow)
    .ToTask(2d, 2d)
    .ContinueWith(x => ((Action<string, object[]>)Console.WriteLine).ToTask("Power value: {0}", new object[] { x.Result }))
    .Wait();
Console.WriteLine("Program completed.");
Console.ReadLine();