V
Vivek Waghmare
Hi
My purpose to create an application which should not allowed to run more
than one instance of it.
I have acheived this by doing following steps
1. Created a class named SingleInstance inherhated from
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
2. override method OnCreateMainForm
this.MainForm = new MainForm();
if(this.CommandLineArgs != null && this.CommandLineArgs.Count > 0)
{
((MainForm)this.MainForm).ProcessArguments(this.CommandLineArgs);
( (MainForm) this.MainForm ).BringToFront();
}
3. overrdie method OnStatupNextInstance
protected override void
OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs
eventArgs)
{
base.OnStartupNextInstance(eventArgs);
eventArgs.BringToForeground = true;
try
{
this.OpenForms["CustomizationWizardForm"].Activate();
}
catch
{
//This try-catch block is used to avoid exception that will arise when one
instacne is running and
//user clicks on another FR project or same exe
}
if(eventArgs.CommandLine != null && eventArgs.CommandLine.Count > 0)
{
if(this.MainForm != null)
{
( (MainForm) this.MainForm ).ProcessArguments(eventArgs.CommandLine);
}
}
}
4. In Main method
created instance of SingleInstance
SingleInstance singleInstance = new SingleInstance();
singleInstance.Run(args);
I am getting my required result, Any new instance of my application is now
presvented.
But i am facing a strange problems
When launched my application does not get focus. Its maxmized but without
focus, and it starts blinking in orange in taskbar.
Please help
My purpose to create an application which should not allowed to run more
than one instance of it.
I have acheived this by doing following steps
1. Created a class named SingleInstance inherhated from
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
2. override method OnCreateMainForm
this.MainForm = new MainForm();
if(this.CommandLineArgs != null && this.CommandLineArgs.Count > 0)
{
((MainForm)this.MainForm).ProcessArguments(this.CommandLineArgs);
( (MainForm) this.MainForm ).BringToFront();
}
3. overrdie method OnStatupNextInstance
protected override void
OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs
eventArgs)
{
base.OnStartupNextInstance(eventArgs);
eventArgs.BringToForeground = true;
try
{
this.OpenForms["CustomizationWizardForm"].Activate();
}
catch
{
//This try-catch block is used to avoid exception that will arise when one
instacne is running and
//user clicks on another FR project or same exe
}
if(eventArgs.CommandLine != null && eventArgs.CommandLine.Count > 0)
{
if(this.MainForm != null)
{
( (MainForm) this.MainForm ).ProcessArguments(eventArgs.CommandLine);
}
}
}
4. In Main method
created instance of SingleInstance
SingleInstance singleInstance = new SingleInstance();
singleInstance.Run(args);
I am getting my required result, Any new instance of my application is now
presvented.
But i am facing a strange problems
When launched my application does not get focus. Its maxmized but without
focus, and it starts blinking in orange in taskbar.
Please help