动画GIF请等待
问题描述:
我有一个请等待一个窗口应用程序,在一个长时间运行的任务之前呈现的请稍候形式,请等待包含一个动画gif,需要在这个过程中“旋转”,但我无法得到这项工作。动画GIF请等待
我终于得到了正确显示形式使用下面的代码:
frmChooser chooser = frmChooser.Instance;
chooser.Url = this.UrlTextBox.Text;
frmBuildNotification fb = new frmBuildNotification();
fb.Show(this);
fb.Update();
Application.DoEvents();
chooser.BuildTreeView();
fb.Close();
this.Hide();
chooser.Show(this);
的GIF包含在frmBuildNotification
一个PictureBox
控制范围之内,我读的地方,你需要重绘图像的形式为动画,但这似乎有点乏味?
答
您需要保持DoEvents消息泵继续运行,并且如果您将通知表单放在另一个线程上,它也会有所帮助。试试这个:
bool done = false;
frmBuildNotification fb = null;
ThreadPool.QueueUserWorkItem((x) =>
{
using (fb = new frmBuildNotification())
{
fb.Show();
while (!done)
Application.DoEvents();
fb.Close();
}
});
frmChooser chooser = frmChooser.Instance;
chooser.Url = this.UrlTextBox.Text;
chooser.BuildTreeView();
done = true;
this.Hide();
chooser.Show(this);
线程一次只能做一件事。它不能建立treeview并保持gif动画。使用BackgroundWorker准备数据。或者使用闪屏。 – 2012-03-15 19:41:58