Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class MainWindow : Window
- {
- private CancellationTokenSource tokenSource = new CancellationTokenSource();
- public MainWindow()
- {
- InitializeComponent();
- PrintButtonText("None");
- }
- private void PrintButtonText(string buttonText)
- {
- Console.WriteLine("Update!");
- Task.Factory.StartNew(() =>
- {
- while (!tokenSource.Token.IsCancellationRequested)
- {
- Console.WriteLine("Button Pressed Text: " + buttonText);
- }
- }, tokenSource.Token);
- }
- private void Button1_Click(object sender, RoutedEventArgs e)
- {
- tokenSource.Cancel();
- PrintButtonText("Button1");
- }
- private void Button2_Click(object sender, RoutedEventArgs e)
- {
- tokenSource.Cancel();
- PrintButtonText("Button2");
- }
- }
- tokenSource.Cancel();
- PrintButtonText("Button1");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement