本文整理汇总了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());
}
});
}
示例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);
}
示例3: TaskWithResult
public void TaskWithResult()
{
Task<string> t = new WebClient().DownloadStringTaskAsync("http://squeed.com");
t.ContinueWith(_ => Console.WriteLine("Task result: " + t.Result));
}
示例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);
}