-1
I have a method void
that performs a procedure in the database and has no return, call this method in the load of the form, however when the procedure delays the program.
How do I pass this method to async
not to curb implementation?
private void AccountsReceivable()
{
using (SqlConnection con = clsdb.AbreBanco())
{
using (SqlCommand cmd1 = new SqlCommand("procedimento", con))
{
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.CommandTimeout = 20000;
cmd1.ExecuteNonQuery();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
Task Receivable = new Task(AccountsReceivable);
Receivable.Start();
}
if you change the method to async, "Form_load" should also be, otherwise you will need to use a
Wait
, which will force the other method to be synchronous... you can start a new task and let it run without blocking the processing. You can do this for example by usingTask.Run
– Ricardo Pontual
@Ricardopunctual Can you give me an example using the code above, I didn’t understand the part about creating a new
task
and let run without blocking.– mba
@mba this method that you run in the database you say is time consuming and that why you "lock" your program, is that if you improve the query, as for example in a Select with WITH command (NOLOCK) which indicates that it will not be necessary to lock the table while reading the data, would that help?? ex: "SELECT COUNT(Name) FROM Tabelapessoas WITH (NOLOCK) "
– Danielle Arruda torres