You can also look at my article at http://www.dalepreston.com/Blog/2005/03/you-only-run-once.html for an
alternative method that will send any command line arguments on the second
instance to the first instance before shutting down the second instance.
There's one more good solution I'd like to suggest but I can't find it. It
is from a regular on the groups that has a site with a great Graphics
namespace help too. I can't find the site but if you can, his solution is
very simple if you don't need to do the message passing that my solution does.
In v1.x I used to do this with a Mutex object. I've not looked at how to do
this in v2 yet, but I believe your question has already been answered by
Nicholas and Dale.
Occasionally, just occasionally, I sometimes yearn for VB's simplicity...
App.PrevInstance was a classic, wasn't it...?
Actually, I started using the Mutex method in VB apps years ago because
App.PreviousInstance was not reliable. It was common for applications to be
able to be run twice because of timing issues.
My original inspiration for the Mutex method was an article on mvps.org
years ago that described more technical details of what caused the problems
when using App.PreviousInstance. I don't remember that far back too clearly
and the site has changed formats so the old information isn't there anymore.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.