示例#1
0
        public async Task TaskIsCorrectlyScheduledOnStaThread()
        {
            // arrange
            ApartmentState?receivedState = null;
            var            act           = new Action(() => { receivedState = Thread.CurrentThread.GetApartmentState(); });

            // act
            await StaTask.Run(act);

            // assert
            receivedState.Should().NotBeNull();
            receivedState.Should().Be(ApartmentState.STA);
        }
示例#2
0
        public void CancellationTokenIsPassedToTheTask()
        {
            // arrange
            var wasExecuted       = false;
            var act               = new Action(() => { wasExecuted = true; });
            var cancellationToken = new CancellationToken(true);
            var task              = StaTask.Run(act, cancellationToken);
            var taskAct           = new Action(() => task.Start());

            // act
            // assert
            wasExecuted.Should().BeFalse();
            taskAct.Should().Throw <Exception>();
            task.Status.Should().Be(TaskStatus.Canceled);
        }
示例#3
0
        private void BuildFolderIco(IFilmFromFolder film)
        {
            new PosterService().Download(film.Poster, film.PathTo("folder.jpg"), (url, path) =>
                                         MessageBox.Show("Couldn't download folder.jpg for '" + film.Title + "' from url '" + film.Poster + "' to '" + film.PathTo("folder.jpg") + "'", "Error downloading folder.jpg", MessageBoxButton.OK, MessageBoxImage.Error));

            if (!System.IO.File.Exists(film.PathTo("folder.jpg")))
            {
                return;
            }

            Task <Bitmap> task = StaTask.Start <Bitmap>(() => new IconLayout(new IconLayoutViewModel(film.PathTo("folder.jpg"), film.Rating)).RenderToBitmap());

            task.Wait();
            Bitmap icon = task.Result;

            new PngToIcoService().Convert(icon, film.PathTo("folder.ico"));
        }
示例#4
0
 public Task <string> GenerateXaml(double width, double height, IEnumerable <PointCollection> shapes)
 {
     // Need to create the task on the STA thread, otherwise it fails
     // to create the WPF controls.
     return(StaTask.Start <string>(() => InternalGenerateXaml(width, height, shapes)));;
 }