Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16.  
  17. namespace WpfApp1
  18. {
  19.     /// <summary>
  20.     /// Interaction logic for MainWindow.xaml
  21.     /// </summary>
  22.     public partial class MainWindow : Window
  23.     {
  24.         int counter = 0;
  25.  
  26.         public void SomeMethod()
  27.         {
  28.             Task.Delay(10);
  29.             currentThread.Content = "Current thread: " + Thread.CurrentThread.ManagedThreadId
  30.                                   + "Task current id: " + Task.CurrentId;
  31.         }
  32.  
  33.         Task task1;
  34.  
  35.         public MainWindow()
  36.         {
  37.             InitializeComponent();
  38.             myLabel.Content = counter;
  39.  
  40.             mainThread.Content = "Main thread: " + Thread.CurrentThread.ManagedThreadId
  41.                 + "Task current id: " + Task.CurrentId;
  42.            
  43.             task1 = new Task(SomeMethod);
  44.  
  45.         }
  46.  
  47.         private async void myButton_Click(object sender, RoutedEventArgs e)
  48.         {
  49.             counter = counter + 1;
  50.  
  51.             await task1;
  52.             //await Task.Run(() => task1.Start());
  53.             myLabel.Content = counter;
  54.  
  55.  
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement