Thread 동기화 Collection류

|

Collection 에서 제공하는 SyncRoot이용


사용예)


public class ICollectionSync{
 private Int32[ ] intArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 public void SyncRun(){
  ICollection c = intArr;
  lock(c.SyncRoot){
   IEnumerator e = c.GetEnumerator();
   while(e.MoveNext()){
    Console.Write((int)e.Current +"t");
    try{
     Thread.Sleep(20);
    }catch{ }
   }
   Console.WriteLine("요소갯수:{0} ", c.Count);
  }//lock
 }
}//class

And