If you are interested in this article, you may have encountered the following similar exception hints in programming:
1, the thread operation is invalid: it is accessed from a thread that is not creating the control "X". (x is the name of the control)
2, "the operation performed on the control is being invoked from the wrong thread." Use Control.Invoke or Control.BeginInvoke to marshal to the correct thread to perform this operation. "
Seeing this hint is most likely caused by a control that is accessed across threads. As a small example,
The code is as follows:
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Using System.Threading;
Namespace WindowsFormsApplication6
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
public delegate void MyMethod (); Declares a delegate so that other threads access the
Button
private void Button1_Click (object sender, EventArgs e)
{
Thread AAA = new Thread (new ThreadStart (Opendialogonotherthread));
Aaa. Start ();
}
Other Threads Open dialog box
void Opendialogonotherthread ()
{
MyMethod OpenDialog = new MyMethod (this. OpenDialog);
This. Invoke (OpenDialog); On the current thread, call OpenDialog
}
Open a dialog box
void OpenDialog ()
{
OpenFileDialog OpenFileDialog = new OpenFileDialog ();
Openfiledialog.showdialog ();
}
}
}