Rashmi dev

Rashmi dev

  • NA
  • 12
  • 5.5k

performance improvement

Feb 24 2014 11:50 PM

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SpotTheSlipup_Week1

{

    class Program

    {

        static void Main(string[] args)

        {

            EventProvider eventProvider = new EventProvider();

            for (int counter = 0; counter <= 2000; counter++)

            {

                //Attach the event

                EventConsumer Gc = new EventConsumer(eventProvider);

                Gc = null;

                GC.Collect();

                long memoryUsed = GC.GetTotalMemory(true);

                Console.WriteLine("Total Memory Used: " + memoryUsed + " bytes");

            }

 

            Console.ReadLine();

 

        }

    }

   

    public class EventProvider

    {

        public event EventHandler SomeEventRaised;

    }

 

    public class EventConsumer

    {

        private EventProvider eventProvider;

 

        public EventConsumer(EventProvider eventRaiser)

        {

            this.eventProvider = eventRaiser;

            eventProvider.SomeEventRaised += raiser_SomeEventRaised;

        }

 

        private void raiser_SomeEventRaised(object sender, EventArgs e)

        {

            //do something

        }

    }

 

 

}


Answers (2)