Saturday, December 5, 2009

Singleton class example in C#

namespace SingletonClass
{
public partial class Form2 : Form
{
static Form2 currentInstance;
private Form2()
{
InitializeComponent();
}
public static Form2 GetForm2()
{
if (currentInstance == null)
{
currentInstance = new Form2();
}
return currentInstance;
}
public void Form_Close(object o, EventArgs e)
{
currentInstance = null;
}
protected override void Dispose(bool disposing)
{
currentInstance = null;
base.Dispose(disposing);
}
}
}

No comments:

Post a Comment