This file contains 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.Threading.Tasks; | |
namespace RStein.Async.Schedulers | |
{ | |
public interface IProxyScheduler | |
{ | |
bool DoTryExecuteTask(Task task); | |
TaskScheduler AsTplScheduler(); | |
} | |
} |
This file contains 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 class ProxyScheduler : TaskScheduler, IProxyScheduler, IDisposable | |
{ | |
private readonly ITaskScheduler m_realScheduler; |
This file contains 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 | |
{ |
This file contains 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 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 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 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 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 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 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); |
OlderNewer