ref StackCrawlMark stackMark)
{
if (asyncResult == null)
- throw new ArgumentNullException("asyncResult");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult);
if (endFunction == null && endAction == null)
- throw new ArgumentNullException("endMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
Contract.Requires((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
if (scheduler == null)
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
Contract.EndContractBlock();
TaskFactory.CheckFromAsyncOptions(creationOptions, false);
object state, TaskCreationOptions creationOptions)
{
if (beginMethod == null)
- throw new ArgumentNullException("beginMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
if (endFunction == null && endAction == null)
- throw new ArgumentNullException("endMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
Contract.Requires((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
TArg1 arg1, object state, TaskCreationOptions creationOptions)
{
if (beginMethod == null)
- throw new ArgumentNullException("beginMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
if (endFunction == null && endAction == null)
- throw new ArgumentNullException("endFunction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endFunction);
Contract.Requires((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
TArg1 arg1, TArg2 arg2, object state, TaskCreationOptions creationOptions)
{
if (beginMethod == null)
- throw new ArgumentNullException("beginMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
if (endFunction == null && endAction == null)
- throw new ArgumentNullException("endMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
Contract.Requires((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
TArg1 arg1, TArg2 arg2, TArg3 arg3, object state, TaskCreationOptions creationOptions)
{
if (beginMethod == null)
- throw new ArgumentNullException("beginMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
if (endFunction == null && endAction == null)
- throw new ArgumentNullException("endMethod");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
Contract.Requires((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
internal static void CompleteFromAsyncResult(IAsyncResult asyncResult)
{
// Validate argument
- if (asyncResult == null) throw new ArgumentNullException("asyncResult");
+ if (asyncResult == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult);
Contract.EndContractBlock();
var promise = asyncResult.AsyncState as FromAsyncTrimPromise<TInstance>;
- if (promise == null) throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndCalledMultiple"), "asyncResult");
+ if (promise == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);
// Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily
var thisRef = promise.m_thisRef;
var endMethod = promise.m_endMethod;
promise.m_thisRef = default(TInstance);
promise.m_endMethod = null;
- if (endMethod == null) throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndCalledMultiple"), "asyncResult");
+ if (endMethod == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);
// Complete the promise. If the IAsyncResult completed synchronously,
// we'll instead complete the promise at the call site.
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction, CancellationToken cancellationToken)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction, TaskContinuationOptions continuationOptions)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction,
CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
CancellationToken cancellationToken)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
TaskContinuationOptions continuationOptions)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
{
// check arguments
TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
//ArgumentNullException of continuationFunction or continuationAction is checked by the caller
Contract.Requires((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) throw new ArgumentNullException("scheduler");
+ if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
Contract.EndContractBlock();
// Check tasks array and make defensive copy
{
// check arguments
TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
//ArgumentNullException of continuationFunction or continuationAction is checked by the caller
Contract.Requires((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) throw new ArgumentNullException("scheduler");
+ if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
Contract.EndContractBlock();
// Check tasks array and make defensive copy
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction, CancellationToken cancellationToken)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction, TaskContinuationOptions continuationOptions)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction,
CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
CancellationToken cancellationToken)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
TaskContinuationOptions continuationOptions)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
{
- if (continuationFunction == null) throw new ArgumentNullException("continuationFunction");
+ if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
{
// check arguments
TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) throw new ArgumentNullException("tasks");
- if(tasks.Length == 0) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
+ if(tasks.Length == 0) ThrowHelper.ThrowArgumentException( ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
//ArgumentNullException of continuationFunction or continuationAction is checked by the caller
Contract.Requires((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) throw new ArgumentNullException("scheduler");
+ if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
Contract.EndContractBlock();
// Call common ContinueWhenAny() setup logic, extract starter
{
// check arguments
TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) throw new ArgumentNullException("tasks");
- if (tasks.Length == 0) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
+ if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
//ArgumentNullException of continuationFunction or continuationAction is checked by the caller
Contract.Requires((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) throw new ArgumentNullException("scheduler");
+ if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
Contract.EndContractBlock();
// Call common ContinueWhenAny setup logic, extract starter
// Also allow RunContinuationsAsynchronously because this is the constructor called by TCS
if ((creationOptions & ~(TaskCreationOptions.AttachedToParent | TaskCreationOptions.RunContinuationsAsynchronously)) != 0)
{
- throw new ArgumentOutOfRangeException("creationOptions");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions);
}
// Only set a parent if AttachedToParent is specified.
{
if (action == null)
{
- throw new ArgumentNullException("action");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
}
Contract.EndContractBlock();
TaskCreationOptions.PreferFairness |
TaskCreationOptions.RunContinuationsAsynchronously)) != 0)
{
- throw new ArgumentOutOfRangeException("creationOptions");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions);
}
#if DEBUG
if (((creationOptions & TaskCreationOptions.LongRunning) != 0) &&
((internalOptions & InternalTaskOptions.SelfReplicating) != 0))
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_ctor_LRandSR"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_ctor_LRandSR);
}
// Assign options to m_stateAndOptionsFlag.
// set m_action to null. We would want to know if this is the reason that m_action == null.
if (IsCompletedMethod(flags))
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_Start_TaskCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_TaskCompleted);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
var options = OptionsMethod(flags);
if ((options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_Start_Promise"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_Promise);
}
if ((options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) != 0)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_Start_ContinuationTask"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_ContinuationTask);
}
// Make sure that Task only gets started once. Or else throw an exception.
if (Interlocked.CompareExchange(ref m_taskScheduler, scheduler, null) != null)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_Start_AlreadyStarted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_AlreadyStarted);
}
ScheduleAndStart(true);
{
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
Contract.EndContractBlock();
var options = OptionsMethod(flags);
if ((options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) != 0)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_RunSynchronously_Continuation"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_Continuation);
}
// Can't call this method on a promise-style task
if ((options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_RunSynchronously_Promise"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_Promise);
}
// Can't call this method on a task that has already completed
if (IsCompletedMethod(flags))
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_RunSynchronously_TaskCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_TaskCompleted);
}
// Make sure that Task only gets started once. Or else throw an exception.
if (Interlocked.CompareExchange(ref m_taskScheduler, scheduler, null) != null)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_RunSynchronously_AlreadyStarted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_AlreadyStarted);
}
// execute only if we successfully cancel when concurrent cancel attempts are made.
{
Contract.Assert((m_stateFlags & TASK_STATE_CANCELED) != 0, "Task.RunSynchronously: expected TASK_STATE_CANCELED to be set");
// Can't call this method on canceled task.
- throw new InvalidOperationException(Environment.GetResourceString("Task_RunSynchronously_TaskCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_TaskCompleted);
}
}
// Validate arguments.
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
Contract.EndContractBlock();
bool isDisposed = (m_stateFlags & TASK_STATE_DISPOSED) != 0;
if (isDisposed)
{
- throw new ObjectDisposedException(null, Environment.GetResourceString("Task_ThrowIfDisposed"));
+ ThrowHelper.ThrowObjectDisposedException(ExceptionResource.Task_ThrowIfDisposed);
}
return CompletedEvent.WaitHandle;
}
// Task must be completed to dispose
if (!IsCompleted)
{
- throw new InvalidOperationException(Environment.GetResourceString("Task_Dispose_NotCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Dispose_NotCompleted);
}
// Dispose of the underlying completion event if it exists
long totalMilliseconds = (long)timeout.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue)
{
- throw new ArgumentOutOfRangeException("timeout");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout);
}
return Wait((int)totalMilliseconds, default(CancellationToken));
{
if (millisecondsTimeout < -1)
{
- throw new ArgumentOutOfRangeException("millisecondsTimeout");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout);
}
Contract.EndContractBlock();
// Throw on continuation with null action
if (continuationAction == null)
{
- throw new ArgumentNullException("continuationAction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
}
// Throw on continuation with null TaskScheduler
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
Contract.EndContractBlock();
// Throw on continuation with null action
if (continuationAction == null)
{
- throw new ArgumentNullException("continuationAction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
}
// Throw on continuation with null TaskScheduler
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
Contract.EndContractBlock();
// Throw on continuation with null function
if (continuationFunction == null)
{
- throw new ArgumentNullException("continuationFunction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
}
// Throw on continuation with null task scheduler
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
Contract.EndContractBlock();
// Throw on continuation with null function
if (continuationFunction == null)
{
- throw new ArgumentNullException("continuationFunction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
}
// Throw on continuation with null task scheduler
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
Contract.EndContractBlock();
TaskContinuationOptions illegalMask = TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.LongRunning;
if ((continuationOptions & illegalMask) == illegalMask)
{
- throw new ArgumentOutOfRangeException("continuationOptions", Environment.GetResourceString("Task_ContinueWith_ESandLR"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_ESandLR);
}
// Check that no illegal options were specified
~(creationOptionsMask | NotOnAnything |
TaskContinuationOptions.LazyCancellation | TaskContinuationOptions.ExecuteSynchronously)) != 0)
{
- throw new ArgumentOutOfRangeException("continuationOptions");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions);
}
// Check that we didn't specify "not on anything"
if ((continuationOptions & NotOnAnything) == NotOnAnything)
{
- throw new ArgumentOutOfRangeException("continuationOptions", Environment.GetResourceString("Task_ContinueWith_NotOnAnything"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_NotOnAnything);
}
// This passes over all but LazyCancellation, which has no representation in TaskCreationOptions
long totalMilliseconds = (long)timeout.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue)
{
- throw new ArgumentOutOfRangeException("timeout");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout);
}
return WaitAll(tasks, (int)totalMilliseconds);
{
if (tasks == null)
{
- throw new ArgumentNullException("tasks");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
}
if (millisecondsTimeout < -1)
{
- throw new ArgumentOutOfRangeException("millisecondsTimeout");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout);
}
Contract.EndContractBlock();
if (task == null)
{
- throw new ArgumentException(Environment.GetResourceString("Task_WaitMulti_NullTask"), "tasks");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks);
}
bool taskIsCompleted = task.IsCompleted;
// Now gather up and throw all of the exceptions.
foreach (var task in tasks) AddExceptionsForCompletedTask(ref exceptions, task);
Contract.Assert(exceptions != null, "Should have seen at least one exception");
- throw new AggregateException(exceptions);
+ ThrowHelper.ThrowAggregateException(exceptions);
}
return returnValue;
// If one or more threw exceptions, aggregate them.
if (exceptions != null)
{
- throw new AggregateException(exceptions);
+ ThrowHelper.ThrowAggregateException(exceptions);
}
}
long totalMilliseconds = (long)timeout.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue)
{
- throw new ArgumentOutOfRangeException("timeout");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout);
}
return WaitAny(tasks, (int)totalMilliseconds);
{
if (tasks == null)
{
- throw new ArgumentNullException("tasks");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
}
if (millisecondsTimeout < -1)
{
- throw new ArgumentOutOfRangeException("millisecondsTimeout");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout);
}
Contract.EndContractBlock();
if (task == null)
{
- throw new ArgumentException(Environment.GetResourceString("Task_WaitMulti_NullTask"), "tasks");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks);
}
if (signaledTaskIndex == -1 && task.IsCompleted)
/// <returns>The faulted task.</returns>
public static Task<TResult> FromException<TResult>(Exception exception)
{
- if (exception == null) throw new ArgumentNullException("exception");
+ if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
Contract.EndContractBlock();
var task = new Task<TResult>();
public static Task FromCanceled(CancellationToken cancellationToken)
{
if (!cancellationToken.IsCancellationRequested)
- throw new ArgumentOutOfRangeException("cancellationToken");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken);
Contract.EndContractBlock();
return new Task(true, TaskCreationOptions.None, cancellationToken);
}
public static Task<TResult> FromCanceled<TResult>(CancellationToken cancellationToken)
{
if (!cancellationToken.IsCancellationRequested)
- throw new ArgumentOutOfRangeException("cancellationToken");
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken);
Contract.EndContractBlock();
return new Task<TResult>(true, default(TResult), TaskCreationOptions.None, cancellationToken);
}
/// <returns>The canceled task.</returns>
internal static Task<TResult> FromCancellation<TResult>(OperationCanceledException exception)
{
- if (exception == null) throw new ArgumentNullException("exception");
+ if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
Contract.EndContractBlock();
var task = new Task<TResult>();
public static Task Run(Func<Task> function, CancellationToken cancellationToken)
{
// Check arguments
- if (function == null) throw new ArgumentNullException("function");
+ if (function == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
Contract.EndContractBlock();
if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource)
public static Task<TResult> Run<TResult>(Func<Task<TResult>> function, CancellationToken cancellationToken)
{
// Check arguments
- if (function == null) throw new ArgumentNullException("function");
+ if (function == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
Contract.EndContractBlock();
if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource)
long totalMilliseconds = (long)delay.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue)
{
- throw new ArgumentOutOfRangeException("delay", Environment.GetResourceString("Task_Delay_InvalidDelay"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.delay, ExceptionResource.Task_Delay_InvalidDelay);
}
return Delay((int)totalMilliseconds, cancellationToken);
// Throw on non-sensical time
if (millisecondsDelay < -1)
{
- throw new ArgumentOutOfRangeException("millisecondsDelay", Environment.GetResourceString("Task_Delay_InvalidMillisecondsDelay"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsDelay, ExceptionResource.Task_Delay_InvalidMillisecondsDelay);
}
Contract.EndContractBlock();
taskArray = new Task[taskCollection.Count];
foreach (var task in tasks)
{
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
taskArray[index++] = task;
}
return InternalWhenAll(taskArray);
}
// Do some argument checking and convert tasks to a List (and later an array).
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
List<Task> taskList = new List<Task>();
foreach (Task task in tasks)
{
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
taskList.Add(task);
}
public static Task WhenAll(params Task[] tasks)
{
// Do some argument checking and make a defensive copy of the tasks array
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
Contract.EndContractBlock();
int taskCount = tasks.Length;
for (int i = 0; i < taskCount; i++)
{
Task task = tasks[i];
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
tasksCopy[i] = task;
}
taskArray = new Task<TResult>[taskCollection.Count];
foreach (var task in tasks)
{
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
taskArray[index++] = task;
}
return InternalWhenAll<TResult>(taskArray);
}
// Do some argument checking and convert tasks into a List (later an array)
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
List<Task<TResult>> taskList = new List<Task<TResult>>();
foreach (Task<TResult> task in tasks)
{
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
taskList.Add(task);
}
public static Task<TResult[]> WhenAll<TResult>(params Task<TResult>[] tasks)
{
// Do some argument checking and make a defensive copy of the tasks array
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
Contract.EndContractBlock();
int taskCount = tasks.Length;
for (int i = 0; i < taskCount; i++)
{
Task<TResult> task = tasks[i];
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
tasksCopy[i] = task;
}
/// </exception>
public static Task<Task> WhenAny(params Task[] tasks)
{
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
if (tasks.Length == 0)
{
- throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
}
Contract.EndContractBlock();
for (int i = 0; i < taskCount; i++)
{
Task task = tasks[i];
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
tasksCopy[i] = task;
}
/// </exception>
public static Task<Task> WhenAny(IEnumerable<Task> tasks)
{
- if (tasks == null) throw new ArgumentNullException("tasks");
+ if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
Contract.EndContractBlock();
// Make a defensive copy, as the user may manipulate the tasks collection
List<Task> taskList = new List<Task>();
foreach (Task task in tasks)
{
- if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks");
+ if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
taskList.Add(task);
}
if (taskList.Count == 0)
{
- throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
}
// Previously implemented CommonCWAnyLogic() can handle the rest
/// <exception cref="T:System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
public bool TrySetException(Exception exception)
{
- if (exception == null) throw new ArgumentNullException("exception");
+ if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
bool rval = m_task.TrySetException(exception);
if (!rval && !m_task.IsCompleted) SpinUntilCompleted();
/// <exception cref="T:System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
public bool TrySetException(IEnumerable<Exception> exceptions)
{
- if (exceptions == null) throw new ArgumentNullException("exceptions");
+ if (exceptions == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exceptions);
List<Exception> defensiveCopy = new List<Exception>();
foreach (Exception e in exceptions)
{
if (e == null)
- throw new ArgumentException(Environment.GetResourceString("TaskCompletionSourceT_TrySetException_NullException"), "exceptions");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NullException, ExceptionArgument.exceptions);
defensiveCopy.Add(e);
}
if (defensiveCopy.Count == 0)
- throw new ArgumentException(Environment.GetResourceString("TaskCompletionSourceT_TrySetException_NoExceptions"), "exceptions");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NoExceptions, ExceptionArgument.exceptions);
bool rval = m_task.TrySetException(defensiveCopy);
if (!rval && !m_task.IsCompleted) SpinUntilCompleted();
/// <exception cref="T:System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
public void SetException(Exception exception)
{
- if (exception == null) throw new ArgumentNullException("exception");
+ if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
if (!TrySetException(exception))
{
- throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
}
}
{
if (!TrySetException(exceptions))
{
- throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
}
}
public void SetResult(TResult result)
{
if (!TrySetResult(result))
- throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
}
/// <summary>
public void SetCanceled()
{
if(!TrySetCanceled())
- throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted"));
+ ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
}
}
}
{
if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
{
- throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating);
}
}
{
if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
{
- throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating);
}
}
{
if (function == null)
{
- throw new ArgumentNullException("function");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
{
- throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating);
}
// Create and schedule the future.
{
if (function == null)
{
- throw new ArgumentNullException("function");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
{
- throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating);
}
// Create and schedule the future.
{
if (continuationAction == null)
{
- throw new ArgumentNullException("continuationAction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
TaskCreationOptions creationOptions;
{
if (continuationAction == null)
{
- throw new ArgumentNullException("continuationAction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
TaskCreationOptions creationOptions;
{
if (continuationFunction == null)
{
- throw new ArgumentNullException("continuationFunction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
TaskCreationOptions creationOptions;
{
if (continuationFunction == null)
{
- throw new ArgumentNullException("continuationFunction");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
}
if (scheduler == null)
{
- throw new ArgumentNullException("scheduler");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
TaskCreationOptions creationOptions;
IDisposable IObservable<TResult>.Subscribe(IObserver<TResult> observer)
{
if (observer == null)
- throw new System.ArgumentNullException("observer");
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.observer);
var continuationTask =
// multiple times for different instantiation.
//
- using System.Runtime.CompilerServices;
+ using Collections.Generic;
+ using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Diagnostics.Contracts;
throw new ObjectDisposedException(objectName, Environment.GetResourceString(GetResourceName(resource)));
}
+ internal static void ThrowObjectDisposedException(ExceptionResource resource)
+ {
+ throw new ObjectDisposedException(null, Environment.GetResourceString(GetResourceName(resource)));
+ }
+
internal static void ThrowNotSupportedException()
{
throw new NotSupportedException();
}
+ internal static void ThrowAggregateException(List<Exception> exceptions)
+ {
+ throw new AggregateException(exceptions);
+ }
+
// Allow nulls for reference types and Nullable<U>, but not for value types.
// Aggressively inline so the jit evaluates the if in place and either drops the call altogether
// Or just leaves null test and call to the Non-returning ThrowHelper.ThrowArgumentNullException
comparer,
endIndex,
keys,
+ creationOptions,
+ timeout,
+ tasks,
+ scheduler,
+ continuationFunction,
+ millisecondsTimeout,
+ millisecondsDelay,
+ function,
+ exceptions,
+ exception,
+ cancellationToken,
+ delay,
+ asyncResult,
+ endMethod,
+ endFunction,
+ beginMethod,
+ continuationOptions,
+ continuationAction,
}
ArgumentOutOfRange_EndIndexStartIndex,
Arg_LowerBoundsMustMatch,
Arg_BogusIComparer,
+ Task_WaitMulti_NullTask,
+ Task_ThrowIfDisposed,
+ Task_Start_TaskCompleted,
+ Task_Start_Promise,
+ Task_Start_ContinuationTask,
+ Task_Start_AlreadyStarted,
+ Task_RunSynchronously_TaskCompleted,
+ Task_RunSynchronously_Continuation,
+ Task_RunSynchronously_Promise,
+ Task_RunSynchronously_AlreadyStarted,
+ Task_MultiTaskContinuation_NullTask,
+ Task_MultiTaskContinuation_EmptyTaskList,
+ Task_Dispose_NotCompleted,
+ Task_Delay_InvalidMillisecondsDelay,
+ Task_Delay_InvalidDelay,
+ Task_ctor_LRandSR,
+ Task_ContinueWith_NotOnAnything,
+ Task_ContinueWith_ESandLR,
+ TaskT_TransitionToFinal_AlreadyCompleted,
+ TaskT_ctor_SelfReplicating,
+ TaskCompletionSourceT_TrySetException_NullException,
+ TaskCompletionSourceT_TrySetException_NoExceptions,
+ InvalidOperation_WrongAsyncResultOrEndCalledMultiple,
}
}