public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Verify dispose interface is implemented in customer class..."); try { int i = TestLibrary.Generator.GetInt32(-55); IntPtr ip = new IntPtr(i); MyResource myRes = new MyResource(ip); myRes.Dispose(); if (myRes.handle != IntPtr.Zero) { TestLibrary.TestFramework.LogError("004", "The handle should be IntPtr.zero!"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("005", "Unexpected exception occurs: " + e); retVal = false; } return(retVal); }
public static void DemoDispose() { using (var res = new MyResource()) { Console.WriteLine("Verwende MyResource"); } // Gleichbedeutend zu: MyResource res2 = new MyResource(); try { Console.WriteLine("Verwende MyResource"); } finally { if (res2 != null) { res2.Dispose(); } } }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Verify dispose interface is implemented in customer class..."); try { int i = TestLibrary.Generator.GetInt32(-55); IntPtr ip = new IntPtr(i); MyResource myRes = new MyResource(ip); myRes.Dispose(); if (myRes.handle != IntPtr.Zero) { TestLibrary.TestFramework.LogError("004","The handle should be IntPtr.zero!"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("005","Unexpected exception occurs: " + e); retVal = false; } return retVal; }