我正在尝试定期轮询服务器并获取 JSON,但由于某种原因,我在正在编写的空白应用程序中看不到参考 System.Timers。这是我的代码
public MainWindow()
{
timer.Tick += new EventHandler(CheckJson_Click_1);
timer.Interval = 30000; //30sec*1000microsec
timer.Enabled = true;
timer.Start();
}
private async void CheckJson_Click_1(object sender, RoutedEventArgs e)
{
var client = new HttpClient();
client.MaxResponseContentBufferSize = 1024 * 1024;
var response = await client.GetAsync(new Uri("URI"));
var result = await response.Content.ReadAsStringAsync();
var component = JsonObject.Parse(result);
}
谁能让我知道我可以用什么代替计时器?