Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Task ScheduleTask(Func<Task> taskFactory)
}
#endif

var source = new TaskCompletionSource<object>();
var source = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);

_tasks.Enqueue(new Entry(taskFactory, source));
_semaphore.Release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ public void Dispose_WhenScheduledTaskExecuting()
#pragma warning restore xUnit1031
}

[Fact]
public void ScheduleTask_InlineContinuationDoesNotDeadlock()
{
var timeout = TimeSpan.FromMilliseconds(250);
using var scheduler = new ScheduledTaskExecutor();

var firstTask = scheduler.ScheduleTask(() => Task.CompletedTask);

var continuationTask = firstTask.ContinueWith(
_ =>
{
var secondTask = scheduler.ScheduleTask(() => Task.CompletedTask);
secondTask.Wait(timeout);
},
CancellationToken,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);

continuationTask.Wait(timeout).ShouldBeTrue();
}

[Fact]
public async Task Dispose_EnsureNoBackgroundProcessing()
{
Expand Down