I have a method that looks like this:
public void SomeMethod()
{
foreach (SomeModel x in TheListOfSomeModel)
{
do some work
....
if (SomeCondition)
{
x.ExecuteQuery();
}
}
}
Basically, SomeModel has a method that runs an update query that stores a property of the object into a field in the database. As the code is currently written, if the query needs to run, the whole loop is on hold until the query is done. If if can be of any use, there are only 5 elements in TheListOfSomeModel.
Apart from using Parrallel ForEach, how can I change this so that the x.ExecuteQuery() runs on a separate thread?
Thanks.
You can run it as a task like this…