예제 #1
0
        private static void CreateChildren(Parent parent)
        {
            var kids = Enumerable.Range(0, 10)
                                 .Select(n => new Child(parent))
                                 .ToArray();

            Console.WriteLine("Parent poke children");

            parent.RaisePokeChildren();

            Console.WriteLine("Kids going out of scope now");
        }
예제 #2
0
        private static void Main(string[] args)
        {
            var parent = new Parent();

            CreateChildren(parent);
            Console.ReadLine();

            // kids are out of scope, yet...
            Console.WriteLine("Collecting garbage");
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Console.WriteLine("Poking children again");
            parent.RaisePokeChildren();
            Console.ReadLine();
        }
예제 #3
0
 public Child(Parent parent)
 {
     _parent = parent;
     _parent.PokeChildren += ParentPokedMe;
 }