public async Task AsyncExecuteExceptionFlow() { using var taskScheduler = new ExclusiveThreadTaskScheduler(); var initThreadId = taskScheduler.ManagedThreadId; await Assert.ThrowsExceptionAsync <ArgumentException>(() => { return(Task.Factory.StartNew(function: async() => { await Task.Delay(1); SameThreadIdAssert(initThreadId, $"Task.Factory.StartNew async continue"); throw new ArgumentException(); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.None, scheduler: taskScheduler).Unwrap()); }); }
static async Task RecursionExecuteAsync(ExclusiveThreadTaskScheduler scheduler, int threadId, int count) { if (count == 0) { return; } await Task.Factory.StartNew(function : async() => { await Task.Delay(1); SameThreadIdAssert(threadId, $"Task.Factory.StartNew async RecursionExecute【{count}】"); if (count % 2 == 0) { scheduler.Run(() => { SameThreadIdAssert(threadId, $"ExclusiveThreadTaskScheduler.Run in async【{count}】"); }); } await RecursionExecuteAsync(scheduler, threadId, count - 1); }, cancellationToken : CancellationToken.None, creationOptions : TaskCreationOptions.None, scheduler : scheduler).Unwrap(); }
public async Task AsyncRecursionExecute() { using var taskScheduler = new ExclusiveThreadTaskScheduler(); var initThreadId = taskScheduler.ManagedThreadId; await RecursionExecuteAsync(taskScheduler, initThreadId, 100);