2012-03-16 2 views
1

ユーザーが長時間実行中のプロセスを開始している間に、スピンホイールのアニメーションgifが進行します。 スタートをクリックすると、プロセスが開始され、同じタイムホイールが回転を開始します。C#、winform - Spining Wheelの進行状況が断続的に途切れて再開します。

しかし、問題は、車輪が途中で衝突して再開することです。これは、長時間のプロセスで複数回発生します。それは連続的に回転しているはずです。同じスレッド()でタスクとアニメーションGIFの両方を実行していますが、インジケータは実際の進捗値ではなくアニメーションの画像であるため、)。

コードは、されているプロセスが終了するまで、私はホイールの非interepted連続画面を表示するにはどうすればよい

 this.progressPictureBox.Visible = true; 
     this.Refresh(); // this - an user controll 
     this.progressPictureBox.Refresh(); 
     Application.DoEvents(); 
     OnStartCalibration(); // Starts long running process 
     this.progressPictureBox.Visible = false; 

OnStartCalibration() 
    {  

     int count = 6; 
     int sleepInterval = 5000; 
     bool success = false; 
     for (int i = 0; i < count; i++) 
     { 
      Application.DoEvents(); 
      m_keywordList.Clear(); 
      m_keywordList.Add("HeatCoolModeStatus"); 
      m_role.ReadValueForKeys(m_keywordList, null, null); 
      l_currentValue = (int)m_role.GetValue("HeatCoolModeStatus"); 
      if (l_currentValue == 16) 
      { 
       success = true; 
       break; 
      }  
      System.Threading.Thread.Sleep(sleepInterval); 
     } 
} 

を使用しましたか?

+0

を..あなたは、長時間実行されるプロセスを処理する方法にBackgroundWorkerのをいくつかのコードを投稿してください? BeginInvoke? –

答えて

0

進行状況の表示とタスクを同じスレッドで実行することはできません。 BackgroundWorker

GUIスレッドはProgressChangedイベントを購読し、タスクの更新を通知されます。ここから、進捗状況を適切に更新できます。タスクが完了したときのイベントもあります。

1

あなたはフレームワーク4を使用する場合は、次のコードでOnStartCalibration(); // Starts long running process行置き換える:

BackgroundWorker bgwLoading = new BackgroundWorker(); 
bgwLoading.DoWork += (sndr, evnt) => 
{ 
    int count = 6; 
    int sleepInterval = 5000; 
    bool success = false; 
    for (int i = 0; i < count; i++) 
    { 
     Application.DoEvents(); 
     m_keywordList.Clear(); 
     m_keywordList.Add("HeatCoolModeStatus"); 
     m_role.ReadValueForKeys(m_keywordList, null, null); 
     l_currentValue = (int)m_role.GetValue("HeatCoolModeStatus"); 
     if (l_currentValue == 16) 
     { 
      success = true; 
      break; 
     }  
     System.Threading.Thread.Sleep(sleepInterval); 
    } 
}; 
bgwLoading.RunWorkerAsync(); 
関連する問題