Hi friends,
I have written following program in Csharp windows application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Practice4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void START_Click(object sender, EventArgs e)
{
Thread temp_thread = new Thread(function);
temp_thread.Start();
}
void function()
{
textBox1.Text = textBox1.Text + "Vijay";
}
}
}
The above program was compiled properly. But while executing i am getting following exception after clicking the START button.
Exception:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.
Can any one please tell me how to avoid the above exception?
Regards,
Vijay Bhaskar