Dennisaa

XThread03

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