PC Review


Reply
Thread Tools Rate Thread

SingleInstance

 
 
Vivek Waghmare
Guest
Posts: n/a
 
      26th Mar 2009
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









 
Reply With Quote
 
 
 
 
Arto Viitanen
Guest
Posts: n/a
 
      27th Mar 2009
Vivek Waghmare wrote:
> 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


You can use System.Threading.Mutex. Following code:

bool createdNew;
string mutexName = "Ourprogramname";
Mutex mutex = new Mutex(false, mutexName, out createdNew);
if (!createdNew)
{
MessageBox.Show("There can be only one", "Oops");
Application.Exit();
return;
}

lets only one intance of the program to be run; actually second instance
stops.

--
Arto Viitanen
 
Reply With Quote
 
 
 
 
Vivek Waghmare
Guest
Posts: n/a
 
      27th Mar 2009
Thanks for your input

But this is not my problem. I have acheived of maintaining single instance
of application. I can create

My issue is that our application is not getting activited when it starts.
It stays minimize at taskbar blinking in orange.
"Arto Viitanen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Vivek Waghmare wrote:
>> 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

>
> You can use System.Threading.Mutex. Following code:
>
> bool createdNew;
> string mutexName = "Ourprogramname";
> Mutex mutex = new Mutex(false, mutexName, out createdNew);
> if (!createdNew)
> {
> MessageBox.Show("There can be only one", "Oops");
> Application.Exit();
> return;
> }
>
> lets only one intance of the program to be run; actually second instance
> stops.
>
> --
> Arto Viitanen



 
Reply With Quote
 
Phil Wilson
Guest
Posts: n/a
 
      31st Mar 2009
I think you might be making assumptions about those BringToFront/Foreground
calls, that you can force some app window to be on top of everything else,
but you can't:

http://blogs.msdn.com/oldnewthing/ar...0/9435239.aspx

--
Phil Wilson
Definitive Guide to Windows Installer
http://www.apress.com/book/view/1590592972


"Vivek Waghmare" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for your input
>
> But this is not my problem. I have acheived of maintaining single instance
> of application. I can create
>
> My issue is that our application is not getting activited when it starts.
> It stays minimize at taskbar blinking in orange.
> "Arto Viitanen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Vivek Waghmare wrote:
>>> 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

>>
>> You can use System.Threading.Mutex. Following code:
>>
>> bool createdNew;
>> string mutexName = "Ourprogramname";
>> Mutex mutex = new Mutex(false, mutexName, out createdNew);
>> if (!createdNew)
>> {
>> MessageBox.Show("There can be only one", "Oops");
>> Application.Exit();
>> return;
>> }
>>
>> lets only one intance of the program to be run; actually second instance
>> stops.
>>
>> --
>> Arto Viitanen

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the Namespace for "SingleInstance" Grey Microsoft C# .NET 1 23rd Mar 2004 10:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.