TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ken H
NA
646
360.7k
Inter-thread operation not valid
Feb 18 2014 10:38 PM
hello,
I try to use the Form Controls multithreaded call, the following error occurred:
Inter-thread operation not valid: access it from not create controls "textBox2" thread.
My codes:
private void btnMT_Click(object sender, EventArgs e) {
MessageBox.Show("Now,You still can do some other things.");
SetEnabledForFalse();
Thread t_one = new Thread(new ThreadStart(FunOne));
Thread t_two = new Thread(new ThreadStart(FunTwo));
t_one.Start();
t_two.Start();
SetEnabledForTrue();
}
private void FunOne() {
for (int i = 0; i < 100; i++)
{
textBox1.AppendText(i.ToString()+" ");
Thread.Sleep(500);
}
}
private void FunTwo() {
for (int i = 0; i < 100; i++)
{
textBox2.AppendText(i.ToString() + " ");
Thread.Sleep(500);
}
}
private void SetEnabledForTrue() {
textBox1.Enabled = true;
textBox2.Enabled = true;
btnMT.Enabled = true;
}
private void SetEnabledForFalse(){
textBox1.Enabled = false;
textBox2.Enabled = false;
btnMT.Enabled = false;
}
private void btnOther_One_Click(object sender, EventArgs e){
MessageBox.Show("This btnOther_One_Click,Working...");
}
private void btnOther_two_Click(object sender, EventArgs e){
MessageBox.Show("This btnOther_two_Click,Working...");
}
Thanks.
Reply
Answers (
3
)
Write multi demensional Array from xml to DataGridView
How to run external macro via ADD-in