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.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.Windows.Threading;
- using System.Threading;
- namespace WpfThreading
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- private delegate void SimpleDelegate();
- public MainWindow()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- SimpleDelegate del = new SimpleDelegate(countDown);
- del.BeginInvoke(null, null);//This is called on UI thread, can Invoke directly
- }
- private void countDown()
- {
- for (int i = 5; i >= 0; i--)
- {
- SimpleDelegate del = delegate()
- { this.label1.Content = i; };
- this.Dispatcher.BeginInvoke(DispatcherPriority.Send, del);//Called on the Worker thread, have to Invoke from the dispatcher's standpoint
- //Console.WriteLine(i);
- Thread.Sleep(1000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment