Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Thu Mar 10 15:35:24 CST 2011
Hi John -- <<< Does that in fact lock the list to other objects doing the same thing (getting the list through that property)? >>> You have to lock/synchronize/serialize not the list itself but simultaneous access to the list from different threads. You'd better use special static object variable to implement locking. I will post sample code in my following posting here... Thank you. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 10 ????? 2011 ?. 16:13 To: VBA Subject: [dba-VB] c# lock() I am using multi-threading and need to lock list objects so that two different threads can access them. Do I even need to lock the list inside of the property as follows: public Dictionary<int, clsAZProcessFile> pLstFiles { get { lock (lstFiles) { return lstFiles; } } } or only when I actually access the list? If I create a property to return the list (without locking it in the property) public Dictionary<int, clsAZProcessFile> pLstFiles { get { return lstFiles; } } and I then get a pointer to the list using that property Dictionary<int, clsAZProcessFile> LstFiles; LstFiles = SomeObj.pLstFiles; and I then lock the pointer while using it lock(LstFiles) { do stuff to list here... } Does that in fact lock the list to other objects doing the same thing (getting the list through that property)? IOW is the lock attribute affixed to the list at the list itself so that anything trying to use the list anywhere in the program can see that the list is locked? -- John W. Colby www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com