using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
class MyClass : IDisposable
{
public event EventHandler OnInitialized;
public event EventHandler OnDisposed;
public void Init()
{
// Initialize our state...
EventHandler onInit = OnInitialized;
if (onInit != null)
onInit(this, new EventArgs());
}
public void Dispose()
{
// Release our state...
EventHandler onDisp = OnDisposed;
if (onDisp != null)
onDisp(this, new EventArgs());
}
}
public class MainClass
{
public static void Main(){
using (MyClass f = new MyClass())
{
f.OnInitialized += delegate { Console.WriteLine("init"); };
f.OnDisposed += delegate { Console.WriteLine("disposed"); };
f.Init();
}
}
}