Periodically update objects from multiple threads in EF

I have the following script:

I have a database storing jobs that are bound and processed by the server. Access to the database is through the Entity Framework.

The server processes jobs in parallel using multiple threads. To do this, I have one thread that periodically checks for new jobs in the database and distributes them among the worker threads.

Now my problem is that my objects have a Progress property that must be updated by workflows and periodically written to the database.

Workflows often update the property (many times per second), but for my requirements it is enough if the database is updated every few seconds, and I do not want to make many unnecessary updates to the database.

So far, my solution has been for workflows to write progress directly to Entity, and the thread that checks for updates will also push those changes to the database.

My question here is: Is this thread safe from an EF perspective. Can I update Entity properties from one stream and write changes to the database in another stream? Do I need a lock case? Keep in mind that I use the DataContext in only one thread (add the least explicitly since I don't know what the EF does inside when I update the object (non-POCO).

, . , DataContexts, .

- , ?

-, , , , . - Job-Entity , DataContext , Entity . , 2 , ...

, DataContexts?

!

+5
2

:

/ . Job-Executor, .Execute() .

- Job-Entity . Executor , .

, , / .

DataContext , .

DataContext .

+1

, .

, .

, /, . , .

0

All Articles