using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch6_10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = " Number of employees before instantiation: " + Employee.Count;
            // create two Employees; count should become 2
            Employee e1 = new Employee("Ali", "Ahmadi");
            Employee e2 = new Employee("Reza", "Amini");
            // show that count is 2 after creating two Employees
            label1.Text += "\n Number of employees after instantiation: " + Employee.Count;
            // get names of Employees
            label1.Text += "\n Employee 1 : " + e1.FirstName + "  " + e1.LastName;
            label1.Text += "\n Employee 2 : " + e2.FirstName + "  " + e2.LastName;
            // in this example, there is only one reference to each Employee,
            // so the following statements cause the CLR to mark each 
            // Employee object as being eligible for destruction
            e1 = null; // object e1 no longer needed
            e2 = null; // object e2 no longer needed
            GC.Collect(); // ask for garbage collection to occur now
            // wait until the destructors
            // finish writing to the console
            GC.WaitForPendingFinalizers();
            // show Employee count after calling garbage collector and
            // waiting for all destructors to finish
            label1.Text += "\n Number of employe after destruction  " + Employee.Count;
        }
    }
}
