-2

如何通过在 Win 8.1 通用应用程序中调用异步 Web 服务调用来定期更新(即全部 10 个)我的 ViewModel 中的一个类?我尝试使用 DispatcherTimer 但计时器无法处理异步部分。这是我尝试过的代码:

_myTimer = new DispatcherTimer();
_myTimer.Interval = new TimeSpan(0, 0, 10);
_myTimer.Tick += timerTick;

protected async Task timerTick(object sender, object e)
{
    var handler = new HttpClientHandler();

    var client = new System.Net.Http.HttpClient(handler);

    string url = "url";

    using (Stream stream = await client.GetStreamAsync(new Uri(url)))
    {

    }
}
4

1 回答 1

1

您的代码看起来正确。DispatcherTimer 是一个可以操作 UI Thread 的特定计时器(而不是在另一个线程上运行的 Timer 类)。

你想表达什么意思:

the timer can't handle the async part

谢谢!

于 2015-12-18T08:07:39.787 回答