diff --git a/src/Uno.Core.Tests/Threading/FastTaskCompletionSourceFixture.cs b/src/Uno.Core.Tests/Threading/FastTaskCompletionSourceFixture.cs index 700157f..0e0fc7c 100644 --- a/src/Uno.Core.Tests/Threading/FastTaskCompletionSourceFixture.cs +++ b/src/Uno.Core.Tests/Threading/FastTaskCompletionSourceFixture.cs @@ -15,7 +15,6 @@ // // ****************************************************************** using System; -using System.Reactive.Concurrency; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; @@ -442,161 +441,5 @@ public void TestSetExceptionTwice_ThrowException() action.Should().NotThrow(); action.Should().Throw(); } - - [TestMethod] - public void TestContinuationWhenSetResultUsingAnotherSyncContext() - { - var sut = new FastTaskCompletionSource(); - var scheduler = new TestScheduler(); - var threadId = Thread.CurrentThread.ManagedThreadId; - - var isRunning = false; - var error = default(Exception); - - scheduler.Schedule(async () => - { - isRunning = true; - try - { - Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); - - await sut.Task; - - Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); - } - catch (Exception e) - { - error = e; - } - finally - { - isRunning = false; - } - }); - scheduler.Schedule(() => - { - isRunning.Should().BeTrue(); - - SynchronizationContext.SetSynchronizationContext(new ErrorSyncContext()); - sut.SetResult("1234"); - - isRunning.Should().BeFalse(); - if (error != null) - { - ExceptionDispatchInfo.Capture(error).Throw(); - } - }); - - scheduler.AdvanceBy(100); - } - - [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - public void TestContinuationWhenSetExceptionUsingAnotherSyncContext() - { - var sut = new FastTaskCompletionSource(); - var scheduler = new TestScheduler(); - var threadId = Thread.CurrentThread.ManagedThreadId; - - var isRunning = false; - var error = default(Exception); - - scheduler.Schedule(async () => - { - isRunning = true; - try - { - Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); - - await sut.Task; - - Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); - } - catch (Exception e) - { - error = e; - } - finally - { - isRunning = false; - } - }); - scheduler.Schedule(() => - { - isRunning.Should().BeTrue(); - - SynchronizationContext.SetSynchronizationContext(new ErrorSyncContext()); - sut.SetException(new ArgumentNullException("xxx")); - - isRunning.Should().BeFalse(); - if (error != null) - { - ExceptionDispatchInfo.Capture(error).Throw(); - } - }); - - scheduler.AdvanceBy(100); - } - - [TestMethod] - [ExpectedException(typeof(OperationCanceledException))] - public void TestContinuationWhenSetCancelUsingAnotherSyncContext() - { - var sut = new FastTaskCompletionSource(); - var scheduler = new TestScheduler(); - var threadId = Thread.CurrentThread.ManagedThreadId; - - var isRunning = false; - var error = default(Exception); - - scheduler.Schedule(async () => - { - isRunning = true; - try - { - Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); - - await sut.Task; - - Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); - } - catch (Exception e) - { - error = e; - } - finally - { - isRunning = false; - } - }); - scheduler.Schedule(() => - { - isRunning.Should().BeTrue(); - - SynchronizationContext.SetSynchronizationContext(new ErrorSyncContext()); - sut.SetCanceled(); - - isRunning.Should().BeFalse(); - if (error != null) - { - ExceptionDispatchInfo.Capture(error).Throw(); - } - }); - - scheduler.AdvanceBy(100); - } - - private class ErrorSyncContext : SynchronizationContext - { - public override void Post(SendOrPostCallback d, object state) - { - throw new NotSupportedException("Cannot schedule anything on the ErrorSyncContext"); - } - - public override void Send(SendOrPostCallback d, object state) - { - throw new NotSupportedException("Cannot schedule anything on the ErrorSyncContext"); - } - } } } diff --git a/src/Uno.Core/Threading/FastTaskCompletionSource.cs b/src/Uno.Core/Threading/FastTaskCompletionSource.cs index 7cb758e..776477b 100644 --- a/src/Uno.Core/Threading/FastTaskCompletionSource.cs +++ b/src/Uno.Core/Threading/FastTaskCompletionSource.cs @@ -364,25 +364,7 @@ private void SpinUntilTermination() private async Task CreateAsyncTask() { - var originalContext = SynchronizationContext.Current; - try - { - SynchronizationContext.SetSynchronizationContext(ImmediatePostSyncContext.Instance); - - return await this; - } - finally - { - SynchronizationContext.SetSynchronizationContext(originalContext); - } - } - - private class ImmediatePostSyncContext : SynchronizationContext - { - public static ImmediatePostSyncContext Instance { get; } = new ImmediatePostSyncContext(); - - /// - public override void Post(SendOrPostCallback action, object state) => action(state); + return await this; } } } \ No newline at end of file