如何在 Silverlight 中编写每 10 秒执行一次操作的程序?
如何在 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();
但它不起作用。请帮忙。
How to write program in Silverlight that would do something every 10 seconds, eg, process twitter search results? The closest I came up is this:
// 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();
but it not work. plz help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望代码在UI线程上执行,则需要DispatcherTimer。请参阅此帖子。
If you want the code to be excuted on the UI thread, you need
DispatcherTimer
. See this post.您想要使用
System.Threading.Timer
。底部带有示例代码的所有官方文档: http:// msdn.microsoft.com/en-us/library/system.threading.timer.aspxYou want to use
System.Threading.Timer
. All the official documentation with sample code at the bottom: http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx