This is my existing code that stores some data in multiple tables.
using (SqlConnection conn = new SqlConnection("myConnString"))
{
DoWork1(conn);
DoWork2(conc);
DoWork3(conn);
}
To speed up my code, I am trying to get .net TPL support, and I modified my code below
using (SqlConnection conn = new SqlConnection("myConnString"))
{
ParallelOptions pw = new ParallelOptions();
pw.MaxDegreeOfParallelism = Environment.ProcessorCount;
Parallel.Invoke(pw,()=> DoWork1(conn),()=> DoWork2(conc),()=> DoWork3(conn));
}
But that throws me an exception of a fatal internal connection error from the ExecuteNonQuery () method in my data access level. Is my parallel approach wrong?
source
share