2013-05-05 63 views
0

我有这样的代码,它从服务器获取GET并检索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。有什么建议么?

+1

也许看看SignalR – TryingToImprove 2013-05-05 19:53:07

回答

2

使用Timer,间隔为30秒,并附上回调函数以检索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 
}