/// <summary> /// Enqueue a callback as a work item to be invoked with a provided <see cref="TaskEnv"/>. /// </summary> /// <typeparam name="T">Result value type of callback.</typeparam> /// <param name="dispatchQueue">DispatchQueue to enqueue work into.</param> /// <param name="callback">Work item callback.</param> /// <param name="env">Environment for work item invocation.</param> /// <param name="result">Synchronization handle for work item.</param> /// <returns>The synchronization handle provided to the method.</returns> public static Result <T> QueueWorkItemWithEnv <T>(this IDispatchQueue dispatchQueue, Func <T> callback, TaskEnv env, Result <T> result) { if (env == null) { throw new ArgumentException("env"); } dispatchQueue.QueueWorkItem(env.MakeAction(callback, result)); return(result); }