2
Answers

performance improvement

Rashmi dev

Rashmi dev

10y
854
1

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)