我已经设置了一个DispatcherTimer,它在每个tick事件上调用WCF服务。在调用服务之后,我想更新UI而不阻塞它,所以我已经标记了定时器的事件处理程序和使WCF调用async的方法,并在相关位置包含await命令(请参阅代码下面)。但是,UI仍然被阻止。有什么想法吗?
static async void connectivityTimer_Tick(object sender, EventArgs e)
{
Person person = await ServiceClient.GetPersonAsync();
lblText.Text = person.Name;
}
public static async Task<Person> GetPersonAsync()
{
Service.Client client = new Service.Client();
Task<string> serviceResult = client.GetPersonAsync();
string contentResults = await serviceResult;
XmlSerializer serializer = new XmlSerializer(typeof(PersonContainer));
using (TextReader reader = new StringReader(contentResults))
{
return ((PersonContainer)serializer.Deserialize(reader)).Person;
}
}