Running multiple instances of a program

  • Thread starter Thread starter Clark Stevens
  • Start date Start date
C

Clark Stevens

I just finished a WinForms app in VB.NET. I want to allow the user to be
able to run multiple instances of the program like you can with Notepad and
Wordpad. The way it is now, once I run the executable I can not run another
instance as long as the first instance is running. How can I change this
behavior? Thanks.
 
* "Clark Stevens said:
I just finished a WinForms app in VB.NET. I want to allow the user to be
able to run multiple instances of the program like you can with Notepad and
Wordpad. The way it is now, once I run the executable I can not run another
instance as long as the first instance is running. How can I change this
behavior?

What you want to do is the default behavior. Preventing the application
from running more than once would require additional code.
 
Clark,

The default is to allow you to run as many instances as you want.

Create a small test project with 1 form. Run the project in Visual Studio
so the bin directory is created and the .exe is built.

Exit Visual Studio and navigate to the projects bin directory.

Double-Click the .exe and observe the form displays.

Double-Click the .exe again and observe a second form displays.

....

-Sam Matzen
 
Samuel L Matzen said:
Clark,

The default is to allow you to run as many instances as you want.

Create a small test project with 1 form. Run the project in Visual Studio
so the bin directory is created and the .exe is built.

Exit Visual Studio and navigate to the projects bin directory.

Double-Click the .exe and observe the form displays.

Double-Click the .exe again and observe a second form displays.

Okay, I did this and it does run multiple instances. However, I have setup
a shortcut on the desktop which launches the executable in the program's Bin
directory. It is the shortcut that doesn't seem to allow the multiple
instances. Every time I launch the shortcut it doesn't run another instance
of the executable. Is there some settings on the shortcut that I need to
change or something?
 
Clark,

I just created a shortcut and it creates multiple instances.

I can't find anything about a shortcut that would make the application not
launch multiple times.

-Sam Matzen
 
Samuel L Matzen said:
Clark,

I just created a shortcut and it creates multiple instances.

I can't find anything about a shortcut that would make the application not
launch multiple times.

I figured out what is causing this. I have a keyboard shortcut defined for
the shortcut on the desktop. When I press the corresponding keyboard
shortcut it launches the executable as expected. However, when I press the
keyboard shortcut a second time it will not launch again. I can launch
another instance by going to the desktop and double clicking on the
shortcut, but pressing the assigned keyboard shortcut multiple times will
not work. Can you duplicate this?
 
Clark,

* "Clark Stevens said:
I figured out what is causing this. I have a keyboard shortcut defined for
the shortcut on the desktop. When I press the corresponding keyboard
shortcut it launches the executable as expected. However, when I press the
keyboard shortcut a second time it will not launch again. I can launch
another instance by going to the desktop and double clicking on the
shortcut, but pressing the assigned keyboard shortcut multiple times will
not work. Can you duplicate this?

I am able to duplicate this and I think this behavior is "by design".
If the application is not yet started and you press the keyboard
shortcut assigned to the shell link pointing to the application, the
application will be started. If the application is already running and
the shortcut is pressed, the running instance is activated. That's what
the help popup for the shortcut field in the shell link's properties
dialog box is saying.
 
Clark,

Yes, I have observed the behavior you described. You apparently cannot
launch multiple instances with the shortcut key.

-Sam Matzen
 
Herfried K. Wagner said:
I am able to duplicate this and I think this behavior is "by design".
If the application is not yet started and you press the keyboard
shortcut assigned to the shell link pointing to the application, the
application will be started. If the application is already running and
the shortcut is pressed, the running instance is activated. That's what
the help popup for the shortcut field in the shell link's properties
dialog box is saying.

Got it. So I guess there's no way to directly load multiple instances of
the same app using a shortcut key. Hmmm, I really need this capability, so
I'll have to figure something else out. Well, anyway, thanks for your help.
I appreciate it.
 
Create a .CMD script with the following lines in it and associate the
shortcut and shortcut key to your script:

start "path\myapp.exe"
exit

Now your application will be indirectly started each time you press the
shortcut key.

Mike Ober.
 
Samuel L Matzen said:
Clark,

Yes, I have observed the behavior you described. You apparently cannot
launch multiple instances with the shortcut key.

-Sam Matzen

I use keyboard shortcuts quite a bit, and was always annoyed by my Internet
Explorer always opening a new window instead of switching to the existing
one when I used the shortcut.

Using XP, I can assign a keyboard shortcut to IE in my start menu, or to a
shortcut on a desktop, and it always opens a new instance. Doing the same
with a VB.NET program always switches to the open application instance.

Seems that MS is able to do it for themselves, at least. :-)

Best Regards,

Andy
 
Andy Becker said:
Using XP, I can assign a keyboard shortcut to IE in my start menu, or to a
shortcut on a desktop, and it always opens a new instance. Doing the same
with a VB.NET program always switches to the open application instance.

More info... The same experiment with Firefox instead of IE has it acting
the same as a VB.NET application, i.e. only one instance is opened.
Sumpin's up with IE, methinks.

Best Regards,

Andy
 
Back
Top