ICollection.SyncRoot属性

作者:追风剑情 发布于:2015-3-28 15:45 分类:C#

  1. ICollection myCollection = someCollection;
  2. //锁定集合,保证线程安全
  3. lock ( myCollection.SyncRoot ) {
  4. foreach ( object item in myCollection ) {
  5. // Insert your code here.
  6. }
  7. }

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号