Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- 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.Navigation;
- using System.Windows.Shapes;
- namespace WpfApp1
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- int counter = 0;
- public void SomeMethod()
- {
- Task.Delay(10);
- currentThread.Content = "Current thread: " + Thread.CurrentThread.ManagedThreadId
- + "Task current id: " + Task.CurrentId;
- }
- Task task1;
- public MainWindow()
- {
- InitializeComponent();
- myLabel.Content = counter;
- mainThread.Content = "Main thread: " + Thread.CurrentThread.ManagedThreadId
- + "Task current id: " + Task.CurrentId;
- task1 = new Task(SomeMethod);
- }
- private async void myButton_Click(object sender, RoutedEventArgs e)
- {
- counter = counter + 1;
- await task1;
- //await Task.Run(() => task1.Start());
- myLabel.Content = counter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement