如何在 Silverlight 中编写每 10 秒执行一次操作的程序,例如,处理 Twitter 搜索结果?我想到的最接近的是:
// Get and process new twitter search results evey 10 seconds
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (sender, args) =>
{
while (true)
{
//Get results of Twitter Search and process them in the above code
client.DownloadStringAsync(new Uri("http://search.twitter.com/search.json?q=" + keywords + "&show-user=true", UriKind.Absolute));
// wait 10 seconds beofre getting new twits
System.Threading.Thread.Sleep(10000);
}
};
worker.RunWorkerAsync();
但它不起作用。请帮忙。
请您参考如下方法:
如果你想让代码在UI线程上执行,你需要DispatcherTimer。看这个post .
