好的,在我的应用程序中,我需要下载两个数据列表来详细说明它们,但我不知道该怎么做..
我单击一个按钮,然后我认为下载几乎是一起开始的。这对我有好处,不好的是我的应用程序无法理解如何在执行其他任何操作之前等待下载..
我知道有一个设计问题,但我不知道如何解决它..
代码(或多或少)是这样的:
private void button_Click(object sender, RoutedEventArgs e)
{
try
{
WebClient webClient = new WebClient();
Uri uri = new Uri("http://myRESTservice");
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(uri); //this will set a private variableA
dwnl();
doSomething(); //this will do something with A and B
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dwnl()
{
try
{
WebClient webClient = new WebClient();
Uri uri = new Uri("http://myRESTservice/anotherAddress");
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted_B);
webClient.OpenReadAsync(uri); //this will set a private variableB
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
希望你明白这个问题..