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
}
}
}