Synchronize function
4 answers
You don't want to sync functions like Java is a bad idea because they use a locking construct that might interfere with the other. You want to lock the object. Basically, in the class you want to protect, create a private member variable of an object of type
private readonly object lock_ = new object();
Then, in whatever method you need to synchronize, use the lock construct to automatically enter and leave the lock: -
public void SomeMethod()
{
lock(lock_)
{
// ...... Do Stuff .........
}
}
+4
a source to share