我该如何在我的Windows Phone应用程序中从一段时间、foreach、for等循环更新UI?
发布于 2012-09-16 06:24:42
你有没有考虑过为此使用额外的线程?
public MainPage()
{
InitializeComponent();
Thread thread = new Thread(() => ReadFile(/*params*/));
thread.Start();
}
private void ReadFile(/*params*/)
{
while(/*condition*/)
{
/* READ FILE */
//send task to UI thread to add object to list box
Dispatcher.BeginInvoke(() => listBox1.Items.Add("YOUR OBJECT"));
}
}长期的动作发生在非UI线程中,这使得UI线程不会被冻结。在每次循环迭代中,非UI线程通过Dispatcher.BeginInvoke向UI线程发送操作,以将新对象添加到列表框中。
https://stackoverflow.com/questions/12442680
复制相似问题