This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace RStein.Async.Schedulers | |
{ | |
public class IoSchedulerThreadServiceFlags | |
{ | |
public IoSchedulerThreadServiceFlags() | |
{ | |
ResetData(); | |
} | |
public bool IsServiceThread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IoServiceScheduler : TaskSchedulerBase, IAsioTaskService | |
{ | |
public const int REQUIRED_WORK_CANCEL_TOKEN_VALUE = 1; | |
public const int POLLONE_RUNONE_MAX_TASKS = 1; | |
public const int UNLIMITED_MAX_TASKS = -1; | |
private readonly ThreadLocal<IoSchedulerThreadServiceFlags> m_isServiceThreadFlags; | |
private readonly CancellationTokenSource m_stopCancelTokenSource; | |
private readonly BlockingCollection<Task> m_tasks; | |
private readonly object m_workLockObject; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
namespace RStein.Async.Schedulers | |
{ | |
public interface IAsioTaskService : IDisposable | |
{ | |
Task Dispatch(Action action); | |
Task Dispatch(Func<Task> function); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
[ExpectedException(typeof (ObjectDisposedException))] | |
public void QueueTask_When_TaskScheduler_Disposed_Then_Throws_ObjectDisposedException() | |
{ | |
var dummyTask = new Task(() => {}); | |
Scheduler.Dispose(); | |
Scheduler.QueueTask(dummyTask); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public async Task WithTaskFactory_When_Tasks_Are_Queued_Then_All_Tasks_Are_Executed() | |
{ | |
const int NUMBER_OF_TASKS = 8096; | |
int numberOfTasksExecuted = 0; | |
var tasks = Enumerable.Range(0, NUMBER_OF_TASKS) | |
.Select(_ => TestTaskFactory.StartNew(() => Interlocked.Increment(ref numberOfTasksExecuted))).ToArray(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public async Task WithTaskFactory_When_One_Task_Is_Queued_Then_Task_is_Executed() | |
{ | |
bool wasTaskExecuted = false; | |
await TestTaskFactory.StartNew(() => wasTaskExecuted = true); | |
Assert.IsTrue(wasTaskExecuted); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override ITaskScheduler Scheduler | |
{ | |
get | |
{ | |
return m_scheduler; | |
} | |
} | |
protected override IProxyScheduler ProxyScheduler | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace RStein.Async.Schedulers | |
{ | |
public class CurrentThreadScheduler : TaskSchedulerBase | |
{ | |
private const int MAXIMUM_CONCURRENCY_LEVEL = 1; | |
public override int MaximumConcurrencyLevel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace RStein.Async.Schedulers | |
{ | |
public abstract class TaskSchedulerBase : ITaskScheduler | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
namespace RStein.Async.Schedulers | |
{ | |
public interface ITaskScheduler : IDisposable | |
{ | |
int MaximumConcurrencyLevel | |
{ |