Running with only one instance on the computer

pisceswzh

Well-known member
Joined
Mar 19, 2007
Messages
96
Programming Experience
1-3
Hi,

I come up with a problem that when my application runs, I want to prevent the user to open 2 instances of my application, but I don't want really "prevent" the user by telling them that you have another instance is running (I have already succeeded in doing this), I want to activate the main form of the former instance and maybe do sth in that former instance.

I don't know whether I can actually do that. But I think it is just like MS Outlook. When you try to run a second Outlook, the first Outlook you have opened will be activated.

And also, you can using speical parameter when you execute the Outlook, so it can do some special things:

If you have an Outlook instance running, and you execute the following command:
"C:\PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE" /c IPM.Note /m "pisceswzh@gmail.com"
This is essentially no difference to execute a second instance of Outlook, but it will not activate the first instance, but create an new email to the provided email address at the first instance.

I am just wondering how cound a second instance of the application to interfere with the first instance of the application (in the Outlook example, the second instance create an new email in the first instance)?

Any one can provide me with any related resources is appreciated. Thanks!
 
Go to Project Properties, Application tab. Check "Make single instance application". Click "View Application Events" button and choose "StartupNextInstance" event. Investigate "e" parameter of that event (StartupNextInstanceEventArgs) and learn how you can use its BringToForeground and CommandLine properties.
 
Back
Top