Connecting Tech Pros Worldwide Help | Site Map

Make Single Instance Application VS 2005

Newbie
 
Join Date: Apr 2007
Posts: 3
#1: Oct 3 '08
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's Avatar
Site Addict
 
Join Date: Jul 2008
Location: US of A
Posts: 587
#2: Oct 3 '08

re: Make Single Instance Application VS 2005


try the settings tab under property?

joedeene
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#3: Oct 3 '08

re: Make Single Instance Application VS 2005


try this link out. Not the method you are looking for, but a different means to the same end.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,751
#4: Oct 4 '08

re: Make Single Instance Application VS 2005


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

Expand|Select|Wrap|Line Numbers
  1.         /// <summary>
  2.         /// The main entry point for the application.
  3.         /// </summary>
  4.         [STAThread]
  5.         static void Main(string[] commandLine)
  6.         {
  7.             Control.CheckForIllegalCrossThreadCalls = false;
  8.             if (bSplash) SplashScreen.ShowSplashScreen();
  9.             if (bSplash) SplashScreen.SetStatus("Getting Environmental information");
  10.  
  11.             Application.EnableVisualStyles();
  12.             App myApp = new App();
  13.             myApp.Run(commandLine);
  14.         }
  15.     }
  16.  
  17.  
  18.  
  19.     /// <summary>
  20.     ///  We inherit from WindowsFormApplicationBase which contains the logic for the application model, including
  21.     ///  the single-instance functionality.
  22.     /// </summary>
  23.     class App : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
  24.     {
  25.         public App()
  26.         {
  27.             this.IsSingleInstance = true; // makes this a single-instance app
  28.             this.EnableVisualStyles = true; // C# windowsForms apps typically turn this on.  We'll do the same thing here.
  29.             this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses; // the vb app model supports two different shutdown styles.  We'll use this one for the sample.
  30.         }
  31.  
  32.         /// <summary>
  33.         /// This is how the application model learns what the main form is
  34.         /// </summary>
  35.         protected override void OnCreateMainForm()
  36.         {
  37.             this.MainForm = new Form1();
  38.         }
  39.  
  40.  
  41.         /// <summary>
  42.         /// Gets called when subsequent application launches occur.  The subsequent app launch will result in this function getting called
  43.         /// and then the subsequent instances will just exit.  You might use this method to open the requested doc, or whatever 
  44.         /// </summary>
  45.         /// <param name="eventArgs"></param>
  46.         protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)
  47.         {
  48.             base.OnStartupNextInstance(eventArgs);
  49.             //System.Windows.Forms.MessageBox.Show("An attempt to launch another instance of this app was made");
  50.         }
  51.  
  52.     }
  53.  
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.
Reply


Similar .NET Framework bytes