private static void ValidateNewManagedThreadAutoRelease() { Console.WriteLine($"Running {nameof(ValidateNewManagedThreadAutoRelease)}..."); using (AutoResetEvent evt = new AutoResetEvent(false)) { int numReleaseCalls = ObjectiveC.getNumReleaseCalls(); RunScenario(evt); // Trigger the GC and wait to clean up the allocated managed Thread instance. GC.Collect(); GC.WaitForPendingFinalizers(); Assert.AreEqual(numReleaseCalls + 1, ObjectiveC.getNumReleaseCalls()); }
private static void TestAutoRelease() { using (AutoResetEvent evt = new AutoResetEvent(false)) { int numReleaseCalls = ObjectiveC.getNumReleaseCalls(); IntPtr obj = ObjectiveC.initObject(); ThreadPool.QueueUserWorkItem(_ => { ObjectiveC.autoreleaseObject(obj); evt.Set(); }); evt.WaitOne(); // Wait 60 ms after the signal to ensure that the thread has finished the work item and has drained the thread's autorelease pool. Thread.Sleep(60); Assert.AreEqual(numReleaseCalls + 1, ObjectiveC.getNumReleaseCalls()); } }