197 |
197 |
198 isAnotherApplicationInstanceRunning |
198 isAnotherApplicationInstanceRunning |
199 "answer true, if another instance of mzself is currently running. |
199 "answer true, if another instance of mzself is currently running. |
200 For now, it only works under win32, because it uses the underlying mutex mechanism." |
200 For now, it only works under win32, because it uses the underlying mutex mechanism." |
201 |
201 |
202 | lastErrorCode alreadyExists handleAndLastErrorCode verboseTmp | |
202 | lastErrorCode alreadyExists handleAndLastErrorCode | |
203 |
203 |
204 OperatingSystem isMSDOSlike ifTrue:[ |
204 OperatingSystem isMSDOSlike ifTrue:[ |
205 verboseTmp := Verbose. |
|
206 Verbose := true. "/ fix for weird bug in expecco which requires Verbose activated |
|
207 handleAndLastErrorCode := OperatingSystem createMutexNamed: (self applicationUUID printString). |
205 handleAndLastErrorCode := OperatingSystem createMutexNamed: (self applicationUUID printString). |
208 MutexHandle := handleAndLastErrorCode first. |
206 MutexHandle := handleAndLastErrorCode first. |
209 lastErrorCode := handleAndLastErrorCode second. |
207 lastErrorCode := handleAndLastErrorCode second. |
210 "/ self assert: lastErrorCode == 0. |
208 "/ self assert: lastErrorCode == 0. |
211 alreadyExists := |
209 alreadyExists := |
212 MutexHandle isNil |
210 MutexHandle isNil |
213 or:[lastErrorCode == 183 "ERROR_ALREADY_EXISTS" |
211 or:[lastErrorCode == 183 "ERROR_ALREADY_EXISTS" |
214 or:[lastErrorCode == 5 "ERROR_ACCESS_DENIED"]]. |
212 or:[lastErrorCode == 5 "ERROR_ACCESS_DENIED"]]. |
215 Verbose := verboseTmp. |
|
216 |
213 |
217 alreadyExists ifFalse:[OperatingSystem waitForSingleObject: MutexHandle]. |
214 alreadyExists ifFalse:[OperatingSystem waitForSingleObject: MutexHandle]. |
218 ^ alreadyExists |
215 ^ alreadyExists |
219 ]. |
216 ]. |
220 |
217 |