I tried a lot: Thread
, DoWork
, Async
Await
, but I got the error:
System.InvalidOperationException: 'Cross-thread operation not valid: Control 'combo' accessed from a thread other than the thread it was created on.'
Here is my code:
public void ggggg()
{
var Names = combo.Text;
string[] strArray = Regex.Split(Names, " - ");
var port = Convert.ToString(strArray[0]);
if (port == "")
{
MessageBox.Show("Please Selcet ", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
MessageBox.Show("Done", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void BtnNames_Click(object sender, EventArgs e)
{
Thread y = new Thread(delegate () { ggggg(); });
y.Start();
}
Another part of the code:
var Names = this.Invoke(new MethodInvoker(delegate { combo.Text = combo.Text.Text + ""; }));;