System.Threading.ReaderWriterLockSlim.LazyCreateEvent C# (CSharp) Method

LazyCreateEvent() final private method

A routine for lazily creating a event outside the lock (so if errors happen they are outside the lock and that we don't do much work while holding a spin lock). If all goes well, reenter the lock and set 'waitEvent'
final private LazyCreateEvent ( EventWaitHandle &waitEvent, bool makeAutoResetEvent ) : void
waitEvent EventWaitHandle
makeAutoResetEvent bool
return void
		void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent)
		{
			Debug.Assert (MyLockHeld);
			Debug.Assert (waitEvent == null);
			
			ExitMyLock ();
			EventWaitHandle newEvent;
			if (makeAutoResetEvent) 
				newEvent = new AutoResetEvent (false);
			else 
				newEvent = new ManualResetEvent (false);

			EnterMyLock ();

			// maybe someone snuck in. 
			if (waitEvent == null)
				waitEvent = newEvent;
		}