CodeForFun
New member
I am poor at explaining myself so please bear with me, I'm trying to understand this, also if it's in the wrong section I do apologise.
So i have a code block like this
In the final actual code, processing takes about 45 seconds per job, as the dataset has increased this has become longer and longer to run.
So I've been trying to make it run, each job as a thread, since the inputs once loaded are not output dependant, when its done the lifting work it calls other code to deal with the result, usually writing back to another table, or in some cases changing the work
entry to mark it as failed etc, but everytime i try to use Parallel.Foreach() i get different types of warning, usually about "eventual consistency" or a second action has started before the first action completed.
And I'm stumped, so can someone explain this to me, it could just be that what I'm trying to do is wrong, and i should find ways to make processing faster (even though that would be a huge amount of work)
Thanks
So i have a code block like this
C#:
public Task DoSomeWork(int batch)
{
IEnumerable<InputWork> work = await _db.InputWork.Where(x => x.Completed == false && x.AwaitingExecution == true).ToListAsync();
foreach (InputWork item in work)
{
// do some work
// just for the stake of it
int mathA = 1;
int mathB = 2;
int result = mathA + mathB;
await SomeHandler.HandleWorkResult(item, result);
// Mark it as complete
item.Completed = true;
item.AwaitingExecution = false;
_db.Entry(item).State = EntityState.Modified()
await _db.SaveChangesAsync();
}
}
In the final actual code, processing takes about 45 seconds per job, as the dataset has increased this has become longer and longer to run.
So I've been trying to make it run, each job as a thread, since the inputs once loaded are not output dependant, when its done the lifting work it calls other code to deal with the result, usually writing back to another table, or in some cases changing the work
entry to mark it as failed etc, but everytime i try to use Parallel.Foreach() i get different types of warning, usually about "eventual consistency" or a second action has started before the first action completed.
And I'm stumped, so can someone explain this to me, it could just be that what I'm trying to do is wrong, and i should find ways to make processing faster (even though that would be a huge amount of work)
Thanks