public void WeakReference() { var radio = new RadioClass(); void CreateChannel() { radio.OpenTwoWay <int, int>(x => x * 2, new object()); } radio.SendTwoWay <int, int>(1).Length.Is(0); for (var i = 0; i < CrossChannelConst.CleanupListThreshold; i++) { CreateChannel(); } GC.Collect(); // Empty list radio.SendTwoWay <int, int>(1).Length.Is(0); var objects = Enumerable.Repeat(new object(), CrossChannelConst.CleanupListThreshold).ToArray(); var number = 0; for (var i = 0; i < CrossChannelConst.CleanupListThreshold; i++) { if (i % 3 == 0) { radio.OpenTwoWay <int, int>(x => x * 2, objects[i]); number++; } else { CreateChannel(); } } GC.Collect(); radio.SendTwoWay <int, int>(1).Length.Is(number); radio.OpenTwoWay <int, int>(x => x * 2, new object()); radio.SendTwoWay <int, int>(1).Length.Is(number + 1); GC.KeepAlive(objects); }
public void Class_TwoWay() { var radio = new RadioClass(); using (var c = radio.OpenTwoWay <int, int>(x => x * 2)) { radio.SendTwoWay <int, int>(1).IsStructuralEqual(new int[] { 2 }); radio.SendTwoWay <int, int>(2).IsStructuralEqual(new int[] { 4 }); using (var d = radio.OpenTwoWay <int, int>(x => x * 2)) { radio.SendTwoWay <int, int>(1).IsStructuralEqual(new int[] { 2, 2 }); radio.SendTwoWay <int, int>(2).IsStructuralEqual(new int[] { 4, 4 }); } radio.SendTwoWay <int, int>(3).IsStructuralEqual(new int[] { 6 }); } radio.SendTwoWay <int, int>(4).IsStructuralEqual(new int[] { }); }
public void WeakDelegate_Static() { var radio = new RadioClass(); void CreateChannel() { radio.OpenTwoWay <int, int>(StaticFunction, new object()); radio.SendTwoWay <int, int>(1).IsStructuralEqual(new int[] { 2 }); } radio.SendTwoWay <int, int>(1).IsStructuralEqual(new int[] { }); CreateChannel(); GC.Collect(); radio.SendTwoWay <int, int>(1).IsStructuralEqual(new int[] { }); }
public InternalClass(RadioClass radio) { radio.OpenTwoWay <int, int>(this.Function, new object()); radio.SendTwoWay <int, int>(1).IsStructuralEqual(new int[] { 2 }); }