2012-03-15 45 views
0

我有一個請等待一個窗口應用程序,在一個長時間運行的任務之前呈現的請稍候形式,請等待包含一個動畫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控制範圍之內,我讀的地方,你需要重繪圖像的形式爲動畫,但這似乎有點乏味?

+0

線程一次只能做一件事。它不能建立treeview並保持gif動畫。使用BackgroundWorker準備數據。或者使用閃屏。 – 2012-03-15 19:41:58

回答

1

您需要保持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);