public void CallbackInvokedMultipleTimes() { int callbackCount = 0; var callbackInvoked = new ManualResetEvent(false); GcNotification.Register(state => { callbackCount++; callbackInvoked.Set(); if (callbackCount < 2) { return(true); } return(false); }, null); GC.Collect(2, GCCollectionMode.Forced, blocking: true); Assert.True(callbackInvoked.WaitOne(100)); Assert.Equal(1, callbackCount); callbackInvoked.Reset(); GC.Collect(2, GCCollectionMode.Forced, blocking: true); Assert.True(callbackInvoked.WaitOne(100)); Assert.Equal(2, callbackCount); callbackInvoked.Reset(); // No callback expected the 3rd time GC.Collect(2, GCCollectionMode.Forced, blocking: true); Assert.False(callbackInvoked.WaitOne(100)); Assert.Equal(2, callbackCount); }
public void CallbackRegisteredAndInvoked() { var callbackInvoked = new ManualResetEvent(false); GcNotification.Register(state => { callbackInvoked.Set(); return(false); }, null); GC.Collect(2, GCCollectionMode.Forced, blocking: true); Assert.True(callbackInvoked.WaitOne(100)); }
public static void Register(Func<object, bool> callback, object state) { var notification = new GcNotification(callback, state); }
public static void Register(Func <object, bool> callback, object state) { var notification = new GcNotification(callback, state); }