Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 public static void Register(Func<object, bool> callback, object state)
 {
     var notification = new GcNotification(callback, state);
 }
Ejemplo n.º 4
0
 public static void Register(Func <object, bool> callback, object state)
 {
     var notification = new GcNotification(callback, state);
 }