C# – cross-threading error example

Snippet

using System.Windows;
using System.Threading;
 
namespace CrossThreadError01 {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
 
        private void button_Click(object sender, RoutedEventArgs e) {
            var thread = new Thread(new ThreadStart(DoCrossThreading));
            thread.Start();
        }
 
        private void DoCrossThreading() {
            textBoxDW.Text = "This text cannot appear";
        }
 
 
    }
}


CrossThreadExample01
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s