WPF下的DispatcherTimer计时器

public DispatcherTimerSample()
		{
			InitializeComponent();
			DispatcherTimer timer = new DispatcherTimer();
			 timer.Tick += new EventHandler(DispatcherTimer_Tick);
			timer.Tick += timer_Tick;
			timer.Start();
		}
///运行一次
		   private   void DispatcherTimer_Tick(object sender, EventArgs e)
        {
            timer.IsEnabled = false;
            //Task t1 = new Task(() => {
            //    MainFangfa();
            //});
            启动Task
            //t1.Start();
           
            Task.Run(async () =>
            { 
                await Dispatcher.InvokeAsync(() =>
                {
                    MainFangfa();
                });
            });
        }

你可能感兴趣的:(wpf)