Pavan Kumar

Pavan Kumar

  • NA
  • 12
  • 3.2k

ProgressBar to stop when button clicked

Jun 25 2020 2:33 PM
I have written code for Progress Bar : Belowprogress  is the code but progress bar has to stop when clicking Stop button can anyone help me in this please :
  1. private void btn_StartLengthyTask_Click(object sender, RoutedEventArgs e)  
  2. {  
  3. pb_LengthyTaskProgress.Value = InitialSleepTime;  
  4. pb_LengthyTaskProgress.Maximum = 100;  
  5. Task.Run(() =>  
  6. {  
  7. for (int i = 0; i < 101; i++)  
  8. {  
  9. this.Dispatcher.Invoke(() => //Use Dispather to Update UI Immediately  
  10. {  
  11. pb_LengthyTaskProgress.Value = i;  
  12. lbl_CountDownTimer.Text = i.ToString();  
  13. });  
  14. Thread.Sleep(ThreadSleepTime) ; // here i have to mention (or) clause for cancel button also.  
  15. }  
  16. });  
  17. } 

Answers (1)