0

我有这个从服务器获取并检索 JSON 的代码。

private async void JSON_click(object sender,RoutedEventArgs e)

    { 
       var client=new HttpClient();
       client.MaxResponseBufferSize=1024*1024;
       var response= await Client.GetAsync(new Uri(The URL here));
       var result = await response.Content.ReadAsStringAsync();

       var component=JsonObject.Parse(result);

    }

我需要每 30 秒轮询一次服务器以检查更新并检索 JSON。有什么建议么?

4

1 回答 1

2

使用Timer30 秒间隔并附加回调函数以检索 JSON。

public void InitTimer()
{
    timer.Elapsed += new EventHandler(GetJSON);
    timer.Interval = 30000; //30sec*1000microsec             
    timer.Enabled = true;                       
    timer.Start();
}

void GetJSON(object sender, EventArgs e)
{
    //Steps to retrieve JSON
}
于 2013-05-05T19:49:14.700 回答