how can i do in C# that my function will be guarded by mutex semaphore a.k.a synchronize function in JAVA
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t want synchronize functions like Java – they’re a bad idea because they use a lock construct which other can interfere with. What you want is a lock object. Basically, in the class you want to protect, create a private member variable of type object
Then in any method you need to synchronize, use the lock construct to enter and leave the lock automatically:-