Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.ComponentModel;
  16. using System.Threading;
  17.  
  18. namespace WpfApp1
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window, INotifyPropertyChanged
  24. {
  25.  
  26. private BackgroundWorker _bgWorker = new BackgroundWorker();
  27.  
  28. private int _workerState;
  29.  
  30. public int WorkerState
  31. {
  32. get { return _workerState; }
  33. set
  34. {
  35. _workerState = value;
  36. if (PropertyChanged != null)
  37. PropertyChanged(this, new PropertyChangedEventArgs("WorkerState"));
  38. }
  39. }
  40.  
  41. public MainWindow()
  42. {
  43. InitializeComponent();
  44.  
  45. DataContext = this;
  46.  
  47. _bgWorker.DoWork += (s, e) =>
  48. {
  49. for (int i = 0; i <= 10; i++)
  50. {
  51. Thread.Sleep(1000);
  52. WorkerState = i;
  53. }
  54. };
  55.  
  56. _bgWorker.RunWorkerAsync();
  57. }
  58.  
  59. public event PropertyChangedEventHandler PropertyChanged;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement