Re: How to allow a specific number of Instances of my app?
- From: "Ralph" <nt_consulting64@xxxxxxxxx>
- Date: Sat, 28 Oct 2006 11:25:17 -0500
"WHoit" <WHoit@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CA3CAE22-2271-49B3-8E2B-FE437782859A@xxxxxxxxxxxxxxxx
pc.
"Ralph" wrote:
"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message
news:-LWdnZbsMed5-d7YnZ2dnUVZ_tWdnZ2d@xxxxxxxxxxxxxxx
"WHoit" <WHoit@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9C71DF09-9269-4E0B-B0FB-0B523D2303BC@xxxxxxxxxxxxxxxx
I need to allow a specific number of instances of my app to run on a
the
For example, I may want to allow someone to run my app 3 times on
andsame
pc.
I don't want to use the "FindWindow" method because it's too weak
thusinaccurate.
I also don't want something that will "linger" if my app crashes,
http://www.vbaccelerator.com/home/VB/Utilities/VBPZip/VBPZip_Source_Code_zip_mMain_bas.aspnot
priorallowing future instances to run (i.e. no writing to files or theregistry).
It also has to be able to handle a user changing the name of the app
to running it (checking running processes won't work in this case).
Does anyone have any suggestions?
Use Mutexs. Only instead of using it for a single instance, create a
"count" - if MutexOne, create MutexTwo, if Two ....
As it
-ralph
On further review, there is a problem with a Mutex if the App crashes.
whenis the responsibility of an App to remove the Mutex to allow another
application to run.
Therefore, as much as it goes against the grain, you may need to invoke
another "clock". ie, create a file/Ini or Registry entry that indicates
needan app starts and when it ends - rather normal for most fault-tolerant
applications. Depending on what your application does, you might even
shutdownto perform an inquiry, a la MS Word - "A previous instance was not
downproperly, would you like to recover the previous file?" or even a brute
force approach - "The app has detected an error, please save and close
ballgame.all apps." Perform your cleanup and restart. ... The list goes on.
Instrumenting an app to be fault-tolerant is a slightly different
mentioned -<g>
-ralph
I was looking into a Mutex, but stopped for the exact reason you
the "crash" factor.the
Isn't there some kind of unique indentifier for my app when it's running
(besides a process id or similar since they're based on names) that I can
look for?
Maybe I can set one (like a Mutex) in memory so that it disappears when
app stops, even by a crash?
I wouldn't mix the two strategies, ie, tracking instances, and
fault-tolerance. They seem related, but will end up with you using two
clocks to measure the same thing, which is always a bad idea. <g>
A mutex is good reliable solution for when everything goes ok. It is also
*usually* a good solution when things go bad as Mutexes are automatically
destroyed by the system when the app terminates, planned or unexpected.
(This kind of answers your last question.) So I would go with a Mutex to
manage instance-counts. And frankly I wouldn't worry that much about it for
the average users/desktop situation. Most users realize if something goes
wrong - a reboot in is their future. <g>
However, whenever an application experiences a "Bad Crash", all bets are are
off.
Fault-tolerance is almost always handled with a classic Watch Dog. Something
that can periodically check and see if everything is a it should be. How you
go about that, again depends entirely on what you need to watch for.
Different scenarios can be complex nightmares or a simple global key. The
question is, do you really need to go there?
Unique identities for your apps is also flexible. Use a shared
file/ini/registry entry. Use shared memory. Use DDE. Use messaging, pipes,
COM+, ... the world is yours. Which you might want or need depends entirely
on your problem domain (critical mission, file editor, server, pda, ...) and
your willingness to go there. <g>
hth
-ralph
.
- Follow-Ups:
- References:
- Prev by Date: Using Volume Shadow Copy Service from VB6
- Next by Date: Re: How to allow a specific number of Instances of my app?
- Previous by thread: Re: How to allow a specific number of Instances of my app?
- Next by thread: Re: How to allow a specific number of Instances of my app?
- Index(es):
Relevant Pages
|