using System; namespace CustomEventConsole { class Class1 { static void Main() { InfoProvider ip = new InfoProvider(); ip.InfoEvent += GotInfo; ip.Start(); } public static void GotInfo(object sender, InfoEventArgs e) { Console.WriteLine(e.Date.ToString()); } } public class InfoEventArgs : EventArgs { private DateTime date; public InfoEventArgs(DateTime date) { this.date = date; } public DateTime Date { get { return date; } } } public class InfoProvider { public event EventHandler InfoEvent; //Note: the generic System.EventHandler is defined like this: // public delegate void EventHandler // (object sender, TEventArgs e) where TEventArgs : EventArgs; public void Start() { DateTime start; TimeSpan span; for (int i = 0; i < 5; i++) { start = DateTime.Now; do { span = DateTime.Now - start; } while (span.Seconds < 1); DateTime date = DateTime.Now; InfoEventArgs args = new InfoEventArgs(date); HaveInfo(args); } } protected void HaveInfo(InfoEventArgs args) { if (InfoEvent != null) InfoEvent(this, args); //If you are using threads, search the .NET docs for //EventHandler delegate //to see how to avoid a possible thread safety issue. } } }