Advertisement
Dennisaa

XThread04

Oct 3rd, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System.Windows;
  2.  
  3. namespace WpfCrossThread {
  4.  
  5.     public partial class MainWindow : Window {
  6.         private delegate void EnterTextDelegate();
  7.         public MainWindow() {
  8.             InitializeComponent();
  9.         }
  10.  
  11.         private void button_Click(object sender, RoutedEventArgs e) {
  12.             var del = new EnterTextDelegate(EnterText);
  13.             del.BeginInvoke(null, null);
  14.         }
  15.  
  16.         private void EnterText() {
  17.             if (MyTextBox.Dispatcher.CheckAccess()) {
  18.                 MyTextBox.Text = "this may make it fail... or will it?";
  19.             } else {
  20.                 var del = new EnterTextDelegate(EnterText);
  21.                 MyTextBox.Dispatcher.BeginInvoke(del);
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement