Skip to content

Instantly share code, notes, and snippets.

@dtryon
Created March 29, 2012 22:23
Show Gist options
  • Save dtryon/2244355 to your computer and use it in GitHub Desktop.
Save dtryon/2244355 to your computer and use it in GitHub Desktop.
Simple action event
using System;
public class OnLoadTest
{
static void Main()
{
Page page = new Page();
//Wire up the event delegate
page.Load += new Action<object, EventArgs>(MyHandler);
//Fire the event
page.Initialize();
Console.WriteLine("Press <enter> to quit");
Console.ReadLine();
}
static void MyHandler(object sender, EventArgs e)
{
Console.WriteLine("In MyHandler");
}
}
public class Page
{
public void Initialize()
{
//Do a few things
OnLoad();
}
public event Action<object, EventArgs> Load;
protected void OnLoad()
{
if (Load != null)
{
EventArgs args = new EventArgs();
Load(this, args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment