educative.io

Educative

The last code snippet fails

using System;
using System.Threading;

class Demonstration
{
static void Main()
{
// First argument is name of the mutex
// and second specifies if the thread
// creating the mutex should also own it
Mutex mutex = new Mutex("", false);
try {
mutex.WaitOne();
// Critical section
}
catch(Exception e) {
// Handle exceptions here
}
finally {
// REMEMBER TO RELEASE THE MUTEEX IN THE
// FINALLY BLOCK
mutex.ReleaseMutex();
}

}

}

the last code snippet fails to run with error:

main.cs(11,23): error CS1502: The best overloaded method match for System.Threading.Mutex.Mutex(bool, string)' has some invalid arguments /usr/lib/mono/4.5/mscorlib.dll (Location of the symbol related to previous error) main.cs(11,33): error CS1503: Argument #1’ cannot convert string' expression to type bool’

Hi @Vishay_Vanjani

Could you please specify the lesson in which this code is making the issue?

Course : C# concurrency for senior Engineering Interviews
Section : API overview
Lesson : Mutex ( Last code snippet , code snippet before Q1