Ejemplo n.º 1
0
        public void EachReportedProgressValueInvokesTheAction()
        {
            int             value    = 0;
            IProgress <int> progress = new ImmediateProgress <int>(v => value = v);

            Assert.Equal(0, value);
            progress.Report(240);
            Assert.Equal(240, value);
            progress.Report(-240);
            Assert.Equal(-240, value);
        }
Ejemplo n.º 2
0
        public async Task CallbacksAreInvokedSynchronously_NeitherThroughSynchronizationContextNorOnTheThreadPool()
        {
            Thread?thread = null;
            IProgress <object?> progress = new ImmediateProgress <object?>(value => thread = Thread.CurrentThread);

            Assert.Null(thread);
            progress.Report(null);
            Assert.NotNull(thread);
            Assert.Same(Thread.CurrentThread, thread);

            TaskCompletionSource <int> tcs = new();

            progress = new Progress <object?>(value => tcs.SetResult(Thread.CurrentThread.ManagedThreadId));

            progress.Report(null);
            int threadId = await tcs.Task.ConfigureAwait(false);

            Assert.NotEqual(Thread.CurrentThread.ManagedThreadId, threadId);
        }