Example #1
0
 public void TaskWithException()
 {
     Task<string> t = new WebClient().DownloadStringTaskAsync("http://squeed.com.invalidAddress");
     t.ContinueWith(_ =>
     {
         //Console.WriteLine(t.Result);
         if (t.IsFaulted)
         {
             Console.WriteLine("Task exception: " + t.Exception.ToString());
         }
     });
 }
Example #2
0
        public void Should_be_able_to_handle_async_tasks_in_sequence()
        {
            bus.SubscribeAsync<MyMessage>("subscribe_async_test_2", message =>
            {
                Console.WriteLine("Got message: {0}", message.Text);
                var firstRequestTask = new WebClient().DownloadStringTask(new Uri("http://localhost:1338/?timeout=100"));

                return firstRequestTask.ContinueWith(task1 =>
                {
                    Console.WriteLine("First Response for: {0}, => {1}", message.Text, task1.Result);
                    var secondRequestTask = new WebClient()
                        .DownloadStringTask(new Uri("http://localhost:1338/?timeout=501"));

                    return secondRequestTask.ContinueWith(task2 =>
                        Console.WriteLine("Second Response for: {0}, => {1}", message.Text, task2.Result));
                });
            });

            // give the test a chance to receive process the message
            Thread.Sleep(2000);
        }
Example #3
0
 public void TaskWithResult()
 {
     Task<string> t = new WebClient().DownloadStringTaskAsync("http://squeed.com");
     t.ContinueWith(_ => Console.WriteLine("Task result: " + t.Result));
 }
        /// <summary>
        /// Download the selected images
        /// </summary>
        private void OnDownloadClick(object sender, EventArgs e)
        {
            var image = SelectedImage;
            if (image == null)
                return;
            var archive = image.Archives.FirstOrDefault();
            if (archive == null)
                return;

            lbProgress.Text = string.Format("Downloading system image {0}...", image.Description);
            lbProgress.Visible = true;
            progress.ProgressType = eProgressItemType.Standard;
            cmdDownload.Enabled = false;
            lvImages.Enabled = true;
            progress.Visible = true;

            var path = Path.GetTempFileName();
            var ui = TaskScheduler.FromCurrentSynchronizationContext();
            var task = new WebClient().DownloadFileTask(new Uri(archive.Url), path, DownloadProgress);
            task.ContinueWith(x => ProcessDownloadImage(x, image, path), ui);
        }