public MainPage()
{
InitializeComponent();
method();//注意:如果2个method写在一个方法里面,调用的时候,2个方法走完才会加载数据,这样用户体验很不好
method1();
}
private async void method()
{
var a = await AsyncCallbac1("http://www.baidu.com");
TbBlock.Text = a;
}
private async void method1()
{
var b = await AsyncCallbac1("http://www.google.com");
TtBlock.Text = b;
}
private async Task AsyncCallbac1(string url)
{
try
{
var hc = new HttpClient();
var hrm = new HttpRequestMessage(HttpMethod.Post, url);
hc.Timeout = TimeSpan.FromSeconds(3);
string cOntent= await (await hc.SendAsync(hrm)).Content.ReadAsStringAsync();
return content;
}
catch (Exception ex)
{
MessageBox.Show("hello");
return null;
}
}