diff options
Diffstat (limited to 'tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs')
-rw-r--r-- | tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs new file mode 100644 index 0000000000..ff36723e14 --- /dev/null +++ b/tests/src/baseservices/threading/semaphore/ctoropen/semaphoreopenneg7.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading; + +class OpenSemaphoreNeg +{ + public static int Main() + { + OpenSemaphoreNeg osn = new OpenSemaphoreNeg(); + return osn.Run(); + } + + private int Run() + { + int iRet = -1; + string sName = Common.GetUniqueName(); + // open a semaphore with the same name as a mutex + EventWaitHandle ewh = new EventWaitHandle(false, + EventResetMode.AutoReset, sName); + try + { + using(Semaphore sem = Semaphore.OpenExisting(sName)) + { + } + } + catch (WaitHandleCannotBeOpenedException) + { + //Expected + iRet = 100; + } + catch (Exception e) + { + Console.WriteLine("Caught unexpected exception: " + + e.ToString()); + } + + Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed"); + return iRet; + } +}
\ No newline at end of file |