LINQ Changeset multi-threading
        Posted  
        
            by Xodarap
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Xodarap
        
        
        
        Published on 2010-05-25T20:06:59Z
        Indexed on 
            2010/05/25
            20:11 UTC
        
        
        Read the original article
        Hit count: 234
        
I'm using LINQ to SQL and after I submit some changes I want to spawn a thread which looks through all the changes and updates our lucene index as necessary. My code looks vaguely like:
(new Thread(() => { UpdateIndex(context.GetChangeSet()); }).Start();
Sometimes though I get an InvalidOperationException, which I think is because context.GetChangeSet() is not thread-safe, and so if the change set is modified in one thread while another thread is enumerating through it, problems arise.
Is there a "thread-safe" version of GetChangeSet()? Or some way I can do ChangeSet.clone() or something?
© Stack Overflow or respective owner