Task.Delay()

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

示例

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.ComponentModel;//INotifyPropertyChanged
  15. using System.Threading.Tasks;
  16.  
  17. namespace WpfTest
  18. {
  19. /// <summary>
  20. /// MainWindow.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. public MainWindow()
  25. {
  26. InitializeComponent();
  27. }
  28.  
  29. private void Button_Click(object sender, RoutedEventArgs e)
  30. {
  31. AsyncWork();
  32. }
  33.  
  34. private async void AsyncWork()
  35. {
  36. Console.WriteLine(DateTime.Now.Second);
  37. await Task.Delay(2000);
  38. Console.WriteLine(DateTime.Now.Second);
  39. await Task.Delay(3000);
  40. Console.WriteLine(DateTime.Now.Second);
  41. }
  42. }
  43. }

运行测试

22222.png

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号