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