Task.Delay()

作者:追风剑情 发布于:2019-8-20 11:00 分类:C#

示例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;//INotifyPropertyChanged
using System.Threading.Tasks;

namespace WpfTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            AsyncWork();
        }

        private async void AsyncWork()
        {
            Console.WriteLine(DateTime.Now.Second);
            await Task.Delay(2000);
            Console.WriteLine(DateTime.Now.Second);
            await Task.Delay(3000);
            Console.WriteLine(DateTime.Now.Second);
        }
    }
}

运行测试

22222.png

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号