Exemplo n.º 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");
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
 public Child(Parent parent)
 {
     _parent = parent;
     _parent.PokeChildren += ParentPokedMe;
 }