当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.ContinueWith方法代码示例

本文整理汇总了C#中System.Net.WebClient.ContinueWith方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.ContinueWith方法的具体用法?C# WebClient.ContinueWith怎么用?C# WebClient.ContinueWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.ContinueWith方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TaskWithException

 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());
         }
     });
 }
开发者ID:Mharlin,项目名称:Demon,代码行数:12,代码来源:TaskOperations.cs

示例2: Should_be_able_to_handle_async_tasks_in_sequence

        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);
        }
开发者ID:siniypin,项目名称:EasyNetQ,代码行数:21,代码来源:SubscribeAsyncTests.cs

示例3: TaskWithResult

 public void TaskWithResult()
 {
     Task<string> t = new WebClient().DownloadStringTaskAsync("http://squeed.com");
     t.ContinueWith(_ => Console.WriteLine("Task result: " + t.Result));
 }
开发者ID:Mharlin,项目名称:Demon,代码行数:5,代码来源:TaskOperations.cs

示例4: OnDownloadClick

        /// <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);
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:24,代码来源:DownloadSystemImagesControl.cs


注:本文中的System.Net.WebClient.ContinueWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。