Quantcast
Channel: CSLA .NET
Viewing all articles
Browse latest Browse all 764

ReadOnlyList fetch with lock

$
0
0

Hi,

This morning I was upgrading CSLA 4.3 to 4.5 and when I ran our application, anything using a ReadOnlyList failed in the DataPortal_Fetch.  I finally found the answer in this thread: http://forums.lhotka.net/forums/p/12449/56992.aspx

OK, easy fix alright.  Except than I ran into some slightly different fetch code.  My boss had been working on making a data loader use threads to speed up the process.  But on occasion, it would fail because a thread could be trying to read a list while one was writing to it (can't remember the exact details, as I wasn't directly working on this).  So we have a number of lists where the DataPortal_Fetch does this:

while (dataReader.Read())
{    currentObject = Word.GetWord(dataReader);    lock (loadingLock)    {        this.Add(currentObject);    }
}

I'm trying to figure out whether I should put the "this.ReadOnly = false" and "... = true" code inside the lock, outside the lock but inside the while, or before/after the while.

Or is the above a big no-no to begin with?

Thanks,
Michel 


Viewing all articles
Browse latest Browse all 764

Trending Articles