// 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; // This is a non-9x test. class WaitAnyEx { WaitHandle[] wh; public static int Main() { WaitAnyEx wae = new WaitAnyEx(); return wae.Run(); } private int Run() { int iRet = -1; Console.WriteLine("Abandoning only one Mutex in array " + "with other WaitHandles, signaling other mutexes"); CreateArray(64); Thread t = new Thread(new ThreadStart(this.AbandonOneAndRelease)); t.Start(); t.Join(); int i = -1; try { Console.WriteLine("Waiting..."); i = WaitHandle.WaitAny(wh); Console.WriteLine("WaitAny did not throw AbandonedMutexExcpetion"); } catch(AbandonedMutexException) { // Expected iRet = 100; } catch(Exception e) { Console.WriteLine("Unexpected exception thrown: " + e.ToString()); } Console.WriteLine(100 == iRet ? "Test Passed" : "Test Failed"); return iRet; } private void AbandonOneAndRelease() { Mutex m = new Mutex(); bool bSet = false; foreach(WaitHandle w in wh) { if(w.GetType() == m.GetType()) { w.WaitOne(); if(bSet) ((Mutex)w).ReleaseMutex(); bSet = true; } } } private void CreateArray(int numElements) { wh = new WaitHandle[numElements]; for(int i=0;i