1
What I’m trying to do is, I need to open another form in another thread where there is a Progress bar that is indeterminated, and in the main ui I need to update the datagrid with the data from the bd after the load is finished.
private async void Disp_data_Sim()
{
var windowToOpen = new WaitingWorker()
{
Owner = this,
};
await Task.Run(new Action(() =>
{
this.BeginInvoke((MethodInvoker)delegate
{
windowToOpen.ShowDialog();
});
try
{
var tempCon = File.ReadAllText("DBConnection.json");
var tempCon1 = Crypt.Decrypt(tempCon, "encryption");
var sqlInfo = new JavaScriptSerializer().Deserialize<SQLInfo>(tempCon1);
using (SqlConnection con = new SqlConnection(sqlInfo.GetConString()))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "SELECT referencia,descricao,pr_custo1,etiqueta,qtd FROM Etiquetas Where etiqueta = @etiqueta";
cmd.Parameters.AddWithValue("@etiqueta", 'S');
DataTable dtbl = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dtbl);
dataGridView1.Invoke(new Action(() => dataGridView1.DataSource = dtbl));
}
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
this.Invoke((MethodInvoker)delegate
{
windowToOpen.Close();
});
}));
}
The problem is this, it runs another form but uses the primary so the program is "unavailable".
Look for
async
this way of doing it is overcome and difficult. In some cases the attempt to backfire and get worse: https://answall.com/q/1946/101– Maniero
I do not want to gain speed, what I want is not to look at the program that does not respond for 10-15sec while the program goes to fetch everything the comic.
– Megaluk