How to avoid multiple instances of windows form in c#

Yes, it has singleton pattern,

Code to create a singleton object,

public partial class Form2 : Form
{
 .....
 private static Form2 inst;
 public static Form2  GetForm
 {
   get
    {
     if (inst == null || inst.IsDisposed)
         inst = new Form2();
     return inst;
     }
 }
 ....
}

Invoke/Show this form,

Form2.GetForm.Show();

Leave a Comment