3
I created a thread to run a process that takes too long and makes the application process stop for a great while
private void ExeConsultaClientes()
{
thread = new Thread(new ThreadStart(ExeConsultaClientesst));
thread.IsBackground = true;
thread.Start();
}
The method the thread executes, is this:
private void ExeConsultaClientesst(){
using (SqlCommand cmd = Program.Conn.CreateCommand())
{
cmd.CommandTimeout = 0;
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
string sql = @" *CONSULTA* ";
cmd.CommandText = sql;
DataSet tabela = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(tabela, "Dados");
*GRIDVIEW*.DataSource = tabela;
*GRIDVIEW*.DataMember =
tabela.Tables[0].TableName.ToString();
*GRIDVIEW*.Refresh();
Cursor.Current = System.Windows.Forms.Cursors.Default;
adp.Dispose();
Program.Conn.Close();
me.FlushMemory();
filterColor();
thread.Suspend();
}
}
When will he access these guys
CubCadastroPivot.DataSource = tabela;
CubCadastroPivot.DataMember = tabela.Tables[0].TableName.ToString();
CubCadastroPivot.Refresh();
Cursor.Current = System.Windows.Forms.Cursors.Default;
adp.Dispose();
Program.Conn.Close();
me.FlushMemory();
filterColor();
It returns the error
Invalid threading operation: control 'GRIDVIEW' accessed from a thread that is not the one it was created on.
There is how to operate with these guys who give error in a method the part accessing the local variables of the method Execonsultclientesst ?
Very correct my good. For some time I’ve been trying to learn, but I didn’t see valid examples for my case. Thankful, hugs !
– Nardier Barbosa
for nothing! arrange
– Rovann Linhalis