Make Single Instance Application VS 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heminfotech
    New Member
    • Apr 2007
    • 3

    Make Single Instance Application VS 2005

    Hi

    I have search for the above said issue and it gives me the same solution that it has option in application properties application tab. But Somehow I am not able to see the same can any one help me please

    Find attached image
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    try the settings tab under property?

    joedeene

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      try this link out. Not the method you are looking for, but a different means to the same end.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Plan B: Use a little code from VB.
        Be sure to add a reference to Microsoft Visual Basic then add this code to your Program.CS file

        Code:
                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                [STAThread]
                static void Main(string[] commandLine)
                {
                    Control.CheckForIllegalCrossThreadCalls = false;
                    if (bSplash) SplashScreen.ShowSplashScreen();
                    if (bSplash) SplashScreen.SetStatus("Getting Environmental information");
        
                    Application.EnableVisualStyles();
                    App myApp = new App();
                    myApp.Run(commandLine);
                }
            }
        
        
        
            /// <summary>
            ///  We inherit from WindowsFormApplicationBase which contains the logic for the application model, including
            ///  the single-instance functionality.
            /// </summary>
            class App : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
            {
                public App()
                {
                    this.IsSingleInstance = true; // makes this a single-instance app
                    this.EnableVisualStyles = true; // C# windowsForms apps typically turn this on.  We'll do the same thing here.
                    this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses; // the vb app model supports two different shutdown styles.  We'll use this one for the sample.
                }
        
                /// <summary>
                /// This is how the application model learns what the main form is
                /// </summary>
                protected override void OnCreateMainForm()
                {
                    this.MainForm = new Form1();
                }
        
        
                /// <summary>
                /// Gets called when subsequent application launches occur.  The subsequent app launch will result in this function getting called
                /// and then the subsequent instances will just exit.  You might use this method to open the requested doc, or whatever 
                /// </summary>
                /// <param name="eventArgs"></param>
                protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)
                {
                    base.OnStartupNextInstance(eventArgs);
                    //System.Windows.Forms.MessageBox.Show("An attempt to launch another instance of this app was made");
                }
        
            }
        You probably want to delete or comment out lines 8 and 9 since they are for a splash screen that won't exist in your project.

        Comment

        Working...