i have this code which does GET from server and retrieves 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);
}
I need to poll server for every 30 seconds to check for updates and retrieve the JSON. Any suggestions?
Use Timer
with 30second interval and attach a callback function to retrieve 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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.