Home > Archive > Smalltalk > May 2004 > Re: How to: prevent another instance of my application being launhed.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: How to: prevent another instance of my application being launhed.
|
|
| Jose Neves 2004-05-12, 7:54 pm |
| delphimaster1@hotmail.com (Jose Neves) wrote in message news:<88ef820.0405040349.86a9c04@posting.google.com>...
> Michel Bany <m.bany@wanadoox.fr> wrote in message news:<408df21c@news.totallyobjects.com>...
>
> Well thats nice but I want to control it inside my application. A user
> can get to and change the command-line option!
>
> Regards,
>
> Jose
Guess no one knows how to huh :)
Regards,
Jose
| |
| Paul Bibbings 2004-05-12, 7:54 pm |
| On 11 May 2004 01:43:20 -0700, delphimaster1@hotmail.com (Jose Neves) wrote:
>delphimaster1@hotmail.com (Jose Neves) wrote in message news:<88ef820.0405040349.86a9c04@posting.google.com>...
>
>
>Guess no one knows how to huh :)
What about something along the lines of the following?
Class: OneInstance
....
Superclass: Object
....
Class instance variables: NoOfInstances
initialize-release
initialize
"Initialize a newly created instance. This method must answer the receiver."
self class noOfInstances: 1.
^self
MetaClass: OneInstance class
Instance variables: NoOfInstances
instance creation
new
"Answer a newly created and initialized instance."
(self noOfInstances = 0)
ifTrue: [
^super new initialize
]
ifFalse: [
^self error: 'Only one instance allowed at a time'
]
accessing
noOfInstances
"Answer NoOfInstances of the receiver."
^NoOfInstances
noOfInstances: aNumber
"Set NoOfInstances to aNumber. Answer of the receiver."
NoOfInstances := aNumber
initialize-release
initialize
"Set NoOfInstances to 0"
self noOfInstances: 0
Of course you would need some way of resetting the class-instance variable upon garbage-collection, but finalization is not something I have got around to next.
Just a thought
PB
| |
| Elliot Finley 2004-05-12, 7:54 pm |
| "Jose Neves" <delphimaster1@hotmail.com> wrote in message
news:88ef820.0405110043.53a60553@posting.google.com...
> delphimaster1@hotmail.com (Jose Neves) wrote in message
news:<88ef820.0405040349.86a9c04@posting.google.com>...
news:<408df21c@news.totallyobjects.com>...[color=darkred]
you[color=darkred]
available[color=darkred]
>
>
> Guess no one knows how to huh :)
It seems like with the windows integration of OS (object studio) you would
be able to access an OS (operating system) level semaphore to accomplish
what you want.
A hackish (is that a word) way of doing it would be to:
1) Create a file (if it doesn't exist) in the root directory, or default
directory.
2) Check to see if you can take an exclusive lock on the file
3) If you can take the lock, take it and hold it (it should be released when
the program exits or crashes :)
2) If you can't take the lock, exit because another instance of your program
is already running.
| |
| Nevin Pratt 2004-05-12, 7:54 pm |
| Elliot Finley wrote:
>
>
> It seems like with the windows integration of OS (object studio) you would
> be able to access an OS (operating system) level semaphore to accomplish
> what you want.
>
> A hackish (is that a word) way of doing it would be to:
>
> 1) Create a file (if it doesn't exist) in the root directory, or default
> directory.
> 2) Check to see if you can take an exclusive lock on the file
> 3) If you can take the lock, take it and hold it (it should be released when
> the program exits or crashes :)
> 2) If you can't take the lock, exit because another instance of your program
> is already running.
>
>
This scheme can also be used with whatever persistence mechanism an app
happens to use, be it a file, RDBMS, ODBMS, or whatever.
Nevin
| |
| dspublic-REMOVE THIS AND HYPENS- 2004-05-12, 7:54 pm |
| Search on Microsofts site, or their news groups reguarding API's. We
did this at one time in our application and then backed it out. There
is an API (I think that it might be in the kernel) you can call that
will tell you if a process is running, Check this in your startup
code, then if you find another instance running, you can gracefully
shut down and warn the user.
Don Stacy
On Tue, 11 May 2004 16:21:50 -0700, Nevin Pratt
<nevin@smalltalkpro.com> wrote:
>Elliot Finley wrote:
>
>
>
>This scheme can also be used with whatever persistence mechanism an app
>happens to use, be it a file, RDBMS, ODBMS, or whatever.
>
>Nevin
| |
| Sascha Doerdelmann 2004-05-12, 7:54 pm |
| Nevin Pratt <nevin@smalltalkpro.com> wrote:
[...]
>
>
> This scheme can also be used with whatever persistence mechanism an app
> happens to use, be it a file, RDBMS, ODBMS, or whatever.
And it is not bound to ObjectStudio. I think you can do this with any
Smalltalk dialect you like.
Cheers
Sascha
|
|
|
|
|