线程互斥 和线程锁的解决

static Mutex myMutex = new Mutex();

 

 

 static public bool writeLine(string instr,string fileName)

{

  myMutex.WaitOne();

 

  .......[做文件读写就行了]

 

  myMutex.ReleaseMutex();

}

  

 private System.Object lockThis = new System.Object();

 lock (lockThis)

        {

            // Access thread-sensitive resources.

        }

  

你可能感兴趣的:(线程)