I have a long running task that benefits from multithreading.
A L2S entity is added to over time by each thread with each thread needing access to properties in that entity.
Because of this requirement of a single instance of the entity, it’s hard to use multiple datacontexts for each thread.
Is there a reccomended way to accomplish such a situation?
Before using Linq to SQL, I was serializing to XML after a set number of paralell iterations. This worked fine, but the data has since become more complicated requiring the relationships/querying available in SQL;
Some Additional Info:
The task is analyzing frames of video to find sequences of similar frames.
There are tables for Media, Frame and Shot.
A Media having multiple Frames and Shots
A Shot having multiple Frames;
Frame extraction and comparison are processor intensive operations and benefit from multithreading.
The issue is, that for each extracted frame. It needs to compare it’s self to the frames before and after it. The before/after frames are likely to come from a seperate thread.
As such, inserting Frames and Shots back into the single Media object being processed would mean combining entities from multiple data contexts into 1.
Instead of solving the parallel Linq issue I changed the process.
Instead of trying to concurrently access the same list of items from multiple threads. I’ve split the list of items and assigned a thread to each section.
This way each thread can act on their own list without bumping into each other.
I’ve then written a finishing method to tidy up the joins between the lists.