synchronized a method

Johnny64 said:
Hey

I have had the same problem as this guy. But he got the answers and so did I :D
http://www.computerhelp.forum/showthread.php?t=72232

But now I have a new problem :p I dont know the C++.NET syntax

all i want to do it lock up a method like you wounld do in Java
Code:
public synchronized void broadcastMessage(String message) {}


Johnny:eek:


use the Monitor class.

e.x.:

Code:
__gc class Foo
{
public:
    void broadcastMessage(System::String* message)
    {
        try
        {
            System::Thread::Monitor::Enter(_locker);
            //do some stuff
        }
        __finally
        {
            System::Thread::Monitor::Exit(_locker);
        }
    }
private:
    static System::Object* _locker;
    static Foo()
    {
        _locker = new System::Object();
    }
};
 
Hey again :p

Does the _locker object have to be static?

And the Monitor class is working, well i dont get any build errors :p

Johnny :D
 
Back
Top