예제 #1
0
        public async Task RunOnBackgroundThreadAsync_should_run_on_the_background_thread()
        {
            bool ranOnUIThread         = false;
            bool ranOnBackgroundThread = false;
            bool ranAction             = false;

            var dispatcher = new ThreadDispatcher(
                uiThreadInvoker: action =>
            {
                ranOnUIThread = true;
                action();
                return(Task.CompletedTask);
            },
                backgroundThreadInvoker: action =>
            {
                ranOnBackgroundThread = true;
                action();
                return(Task.CompletedTask);
            });

            await dispatcher.RunOnBackgroundThreadAsync(() => ranAction = true);

            ranOnUIThread.Should().BeFalse();
            ranOnBackgroundThread.Should().BeTrue();
            ranAction.Should().BeTrue();
        }