//--------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: CurrentThreadTaskScheduler.cs
//
//--------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
namespace System.Threading.Tasks.Schedulers
{
/// Provides a task scheduler that runs tasks on the current thread.
public sealed class CurrentThreadTaskScheduler : TaskScheduler
{
/// Runs the provided Task synchronously on the current thread.
/// The task to be executed.
protected override void QueueTask(Task task)
{
TryExecuteTask(task);
}
/// Runs the provided Task synchronously on the current thread.
/// The task to be executed.
/// Whether the Task was previously queued to the scheduler.
/// True if the Task was successfully executed; otherwise, false.
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
{
return TryExecuteTask(task);
}
/// Gets the Tasks currently scheduled to this scheduler.
/// An empty enumerable, as Tasks are never queued, only executed.
protected override IEnumerable GetScheduledTasks()
{
return Enumerable.Empty();
}
/// Gets the maximum degree of parallelism for this scheduler.
public override int MaximumConcurrencyLevel { get { return 1; } }
}
}