Listing 1: The gclock class.
class gclock { gcroot<System::Object*> m_object; public: gclock( System::Object * object ) : m_object( object ) { System::Threading::Monitor::Enter( object ); } ~gclock() { System::Threading::Monitor::Exit( m_object ); } operator bool() const { return true; } };