Hmm, If you never remove the entries in the hashtable (what you seem to do with the dataTables) you can simplify it like...
Hashtable ht = new Hashtable(); Hashtable locks = new Hashtable(); private object GetLockObject( HashKey key) { object singleLock = locks[key]; if ( singleLock == null) { lock( locks.SynRoot) { singleLock = locks[key]; if ( singleLock == null) { singleLock = new object(); locks[key] = singleLock; } } } return singleLock; } public DataTable GetList( int a, int b, int c) { // lookup the dataTable HashKey key = new HashKey( a, b, c); DataTable dt = (DataTable)ht[key]; if ( dt == null) { // since our last check // the dataTable might be put already // by another thread, so lock and lookup again lock( GetLockObject( key)) { dt = (DataTable)ht[key]; if ( dt == null) { // insert new DataTable dt = GetListLong(a, b, c); ht[key] = dt; return dt; } } } // dataTable exists, but is it still valid? if ( Expired( dt)) { // since our last check // an updated dataTable might be put already // by another thread, so lock and lookup again lock( GetLockObject( key)) { dt = (DataTable)ht[key]; if ( Expired( dt)) { // insert updated DataTable dt = GetListLong(a, b, c); ht[key] = dt; } } } return dt; } HTH // Ryan ------------------------------------- The information included in this message is personal and/or confidential and intended exclusively for the addressees as stated. This message and/or the accompanying documents may contain confidential information and should be handled accordingly. If you are not the intended reader of this message, we urgently request that you notify Centric immediately and that you delete this e-mail and any copies of it from your system and destroy any printouts immediately. It is forbidden to distribute, reproduce, use or disclose the information in this e-mail to third parties without obtaining prior permission from Centric. We expressly point out that there are risks associated with the use of e-mail. Centric and the companies within the group shall not accept any liability whatsoever for damage resulting from the use of e-mail. Legally binding obligations can only arise for Centric by means of a written instrument, signed by an authorized representative of Centric. ------------------------------------- =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com