Social Icons

Sunday, April 25, 2010

Creating Single instance of a windows Form

//Following Code in Child form Class 
//creating form's object.
public static volatile System_Categorization singleObj;

        
// Function in the Form
public static System_Categorization singleInstance()
 {
 if (singleObj == null)
  {
    lock (typeof(System_Categorization))
     {
       if (singleObj == null)
        {
          singleObj = new System_Categorization();
        }
     }
  }
return singleObj;
}

//On Disposing please Please Write following code in Designer class 

protected override void Dispose(bool disposing)
 {
   //mainform objmainform = new mainform();
            
     if (disposing && (components != null))
       {
         components.Dispose();
       }
       base.Dispose(disposing);
     singleObj = null;
           
 }
 
//Following Code in Parent form Class 
// Now open the form as write code in Parent Form
 
 //System_Categorization objForm = new System_Categorization();
System_Categorization.singleInstance().Show(); 

No comments:

Post a Comment

 

Sample text

Sample Text