Writer Lock : ReaderWriterLock : Thread C# Examples


C# Examples » Thread » ReaderWriterLock »

 

Writer Lock









    
using  System;
using  System.Collections.Generic;
using  System.Diagnostics;
using  System.IO;
using  System.Reflection;
using  System.Runtime;
using  System.Runtime.CompilerServices;
using  System.Security;
using  System.Text;
using  System.Threading;

public  class  MainClass
{
        
        public  static  void  Main()
        {
              ReaderWriterLock  rwLock  =  new  ReaderWriterLock();

                rwLock.AcquireWriterLock(250);
                if  (rwLock.IsWriterLockHeld)
                {
                        Console.WriteLine("Writer  lock  held");
                        rwLock.ReleaseWriterLock();
                }

                rwLock.ReleaseWriterLock();

        }
}
    
   
  
   



Output

Writer lock held

Unhandled Exception: System.ApplicationException: Attempt to release mutex not owned by caller. (Exc
eption from HRESULT: 0x00000120)
   at System.Threading.ReaderWriterLock.ReleaseWriterLockInternal()
   at MainClass.Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» ReaderWriterLock