StopWindow.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace ivf_tl_ControlMain
  17. {
  18. /// <summary>
  19. /// StopWindow.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class StopWindow : Window
  22. {
  23. public StopWindow(Window w,int val)
  24. {
  25. InitializeComponent();
  26. MyProperty = val;
  27. Task.Run(() =>
  28. {
  29. bool stop = false;
  30. try
  31. {
  32. while (true)
  33. {
  34. Dispatcher.Invoke(() =>
  35. {
  36. if (MyProperty <= 0)
  37. {
  38. Application.Current.Shutdown();
  39. stop = true;
  40. }
  41. MyProperty--;
  42. //Debug.WriteLine(MyProperty);
  43. });
  44. if (stop)
  45. {
  46. return;
  47. }
  48. Thread.Sleep(999);
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. string sss = ex.Message;
  54. }
  55. });
  56. }
  57. public int MyProperty
  58. {
  59. get { return (int)GetValue(MyPropertyProperty); }
  60. set { SetValue(MyPropertyProperty, value); }
  61. }
  62. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  63. public static readonly DependencyProperty MyPropertyProperty =
  64. DependencyProperty.Register("MyProperty", typeof(int), typeof(StopWindow), new PropertyMetadata(15));
  65. private void Button_Click(object sender, RoutedEventArgs e)
  66. {
  67. this.Close();
  68. }
  69. private void Button_Click1(object sender, RoutedEventArgs e)
  70. {
  71. Application.Current.Shutdown();
  72. }
  73. }
  74. }