internal void MutexTryCode(object userData)
{
SafeWaitHandle mutexHandle = null;
// try block
RuntimeHelpers.PrepareConstrainedRegions();
try
{
}
finally
{
if (m_initiallyOwned)
{
m_cleanupInfo.inCriticalRegion = true;
#if !FEATURE_CORECLR
Thread.BeginThreadAffinity();
Thread.BeginCriticalRegion();
#endif //!FEATURE_CORECLR
}
}
int errorCode = 0;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
}
finally
{
errorCode = CreateMutexHandle(m_initiallyOwned, m_name, m_secAttrs, out mutexHandle);
}
if (mutexHandle.IsInvalid)
{
mutexHandle.SetHandleAsInvalid();
if (m_name != null)
{
switch (errorCode)
{
#if PLATFORM_UNIX
case Win32Native.ERROR_FILENAME_EXCED_RANGE:
// On Unix, length validation is done by CoreCLR's PAL after converting to utf-8
throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", PathInternal.MaxComponentLength), "name");
#endif
case Win32Native.ERROR_INVALID_HANDLE:
throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", m_name));
}
}
__Error.WinIOError(errorCode, m_name);
}
m_newMutex = errorCode != Win32Native.ERROR_ALREADY_EXISTS;
m_mutex.SetHandleInternal(mutexHandle);
m_mutex.hasThreadAffinity = true;
}