using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace ivf_tl_ControlMain { /// /// StopWindow.xaml 的交互逻辑 /// public partial class StopWindow : Window { public StopWindow(Window w,int val) { InitializeComponent(); MyProperty = val; Task.Run(() => { bool stop = false; try { while (true) { Dispatcher.Invoke(() => { if (MyProperty <= 0) { Application.Current.Shutdown(); stop = true; } MyProperty--; //Debug.WriteLine(MyProperty); }); if (stop) { return; } Thread.Sleep(999); } } catch (Exception ex) { string sss = ex.Message; } }); } public int MyProperty { get { return (int)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(int), typeof(StopWindow), new PropertyMetadata(15)); private void Button_Click(object sender, RoutedEventArgs e) { this.Close(); } private void Button_Click1(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } } }