Instances Detection 
Author Message
 Instances Detection

Hi
    If a VFP application is run in a network environment, how can I detect
any other instances of the VFP are currenly running ? Coz certain features
EXCLUSIVELY require single instance.

Thanks in advance.



Mon, 29 Aug 2005 12:39:50 GMT  
 Instances Detection
Hello, BPHQ!
You wrote  on Thu, 13 Mar 2003 12:39:50 +0800:

 BP> Hi
 BP>     If a VFP application is run in a network environment, how can I
 BP> detect any other instances of the VFP are currenly running ? Coz
 BP> certain features EXCLUSIVELY require single instance.

 BP> Thanks in advance.

To detect multiple instances on the network, you can try to use the table in
exclusive mode and catch the error:
lcOldErr = ON("ERROR")
lnErr = 0
ON ERROR lnErr = ERROR()
USE yourtable EXCL && or OPEN DATA yourdbc EXCL
ON ERROR &lcOldErr
IF lnErr # 0
    * error. The error code is in the lnErr var
    * to raise this error:
    * ERROR(lnErr)
ELSE
    * proceed
ENDIF
---
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Mon, 29 Aug 2005 14:19:11 GMT  
 Instances Detection
If you give us some specific examples, I'm sure the ng will help you to work
them out.

-Lew S


Quote:
> Hi
>     If a VFP application is run in a network environment, how can I detect
> any other instances of the VFP are currenly running ? Coz certain features
> EXCLUSIVELY require single instance.

> Thanks in advance.



Mon, 29 Aug 2005 14:21:56 GMT  
 Instances Detection
You could catch an unsucceesful attempt to open the tasble exclusive
In VFP8
TRY
 USE Customers EXCLUSIVE IN 0 ALIAS Customers
CATCH TO oExc
 MESSAGEBOX ('Line '+TRANSFORM(oExc.LineNo)+':'+CHR(13);
 +oExc.LineContents+CHR(13)+' in ';
 +oExc.Procedure,0,'Error message')
* more code
FINALLY
* code
ENDTRY
* ok
-Anders



Quote:
> Hi
>     If a VFP application is run in a network environment, how can I detect
> any other instances of the VFP are currenly running ? Coz certain features
> EXCLUSIVELY require single instance.

> Thanks in advance.



Mon, 29 Aug 2005 18:09:49 GMT  
 Instances Detection
ON ERROR DO exclusiv_error
PACK
ON ERROR DO MyOldErrorPrg

***
PROC Exclusiv_error
IF no_error = ???    &&    I dont known the error, just try it
    DO PleaseCloseTheOtherSession
ENDIF

--
Olivier (enlever les 3X pour la rponse)


Quote:
> You could catch an unsucceesful attempt to open the tasble exclusive
> In VFP8
> TRY
>  USE Customers EXCLUSIVE IN 0 ALIAS Customers
> CATCH TO oExc
>  MESSAGEBOX ('Line '+TRANSFORM(oExc.LineNo)+':'+CHR(13);
>  +oExc.LineContents+CHR(13)+' in ';
>  +oExc.Procedure,0,'Error message')
> * more code
> FINALLY
> * code
> ENDTRY
> * ok
> -Anders



> > Hi
> >     If a VFP application is run in a network environment, how can I detect
> > any other instances of the VFP are currenly running ? Coz certain features
> > EXCLUSIVELY require single instance.

> > Thanks in advance.



Mon, 29 Aug 2005 21:44:26 GMT  
 Instances Detection
You can do the whole thing as follows using a "mutex" (Code initially gotten
from UT if I remember correctly)

1.) Define a class

DEFINE CLASS mutex AS CUSTOM
 hmutex = 0
 nMutexErr = 0
 cFormCaption = ""
 PROCEDURE INIT

 LPARAMETER pcformcaption

 DECLARE INTEGER CreateMutex IN Win32API;

  STRING bInitialOwner,;

 DECLARE INTEGER GetLastError IN Win32API
 LOCAL lcInitOwner, lcname,  lcformcaption
* So that the Mutex name is different
* from the caption.
 lcformcaption = pcformcaption
 lcname = CHRTRAN(pcformcaption, SPACE(1), "")
* Simulate a BOOL type equaling TRUE.
 lcInitOwner = CHR(1)
 WITH THIS
  .cFormCaption = lcformcaption

  .nMutexErr = GetLastError()
 ENDWITH
 RETURN
ENDPROC

2.) at the beginning of your app put

LOCAL oMutex, lcformcaption
_SCREEN.VISIBLE = .F.
* An SDI form should set
* lcformcaption equal to
* the displayed form's caption
* which should not be equal to _SCREEN's
lcformcaption = _SCREEN.CAPTION
_SCREEN.CAPTION = ""
oMutex = CREATEOBJECT('Mutex', lcformcaption)
IF oMutex.nMutexErr # ERROR_ALREADY_EXISTS
* The instance doesn't exist
* and the remaining set up code goes here.
 _SCREEN.VISIBLE = .T.
 _SCREEN.CAPTION = lcformcaption
ELSE
* It does exist so display the
* original before terminating.
 oMutex.DisplayInstance()
 oMutex = .NULL.
 QUIT
ENDIF

3.) at the end of your app (or anyplace it could exit)

oMutex = .NULL.

HTH



Quote:
> Hi
>     If a VFP application is run in a network environment, how can I detect
> any other instances of the VFP are currenly running ? Coz certain features
> EXCLUSIVELY require single instance.

> Thanks in advance.



Mon, 29 Aug 2005 21:55:16 GMT  
 Instances Detection
Using the mutex object is a classical way for an application to determine if
another instance is already runnint on the same machine.
So I'm not really sure if the mutex will work across the network.


Tue, 30 Aug 2005 20:58:32 GMT  
 Instances Detection
Heya - one of the things I've implemented is each time a user fires off the
app -
a file is written to the network folder for that app -
then when the user exists, the file is deleted..
something easy - like
user.1
user.2
user.3
etc etc...
then my app checks for user.* - and if it is there - the exclusive stuff
ain't granted...

This got around having to check for already opened files, doing api calls to
see WHO had the file already opened, etc...
lemme know how that works for you..
hth - mondo regards [Bill]


Quote:
> Hi
>     If a VFP application is run in a network environment, how can I detect
> any other instances of the VFP are currenly running ? Coz certain features
> EXCLUSIVELY require single instance.

> Thanks in advance.



Tue, 30 Aug 2005 23:56:16 GMT  
 Instances Detection
Hi, ILiya!
You wrote  on Fri, 14 Mar 2003 15:58:32 +0300:

 I> Using the mutex object is a classical way for an application to
 I> determine if another instance is already runnint on the same machine.
 I> So I'm not really sure if the mutex will work across the network.

It really won't work :) You have to track this in another way (one of which
is trying to open database or some table in exclusive mode)

WBR, Igor



Wed, 31 Aug 2005 03:45:13 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. DETECTION OF AN OPEN FORM

2. CDROM drive detection

3. Foxpro 2.5 & Error Detection Q's

4. Window detection?

5. mouse detection

6. HELP FPW26.WIN95, Modem detection

7. Ring Detection FoxPro2.5

8. Row Change Detection

9. Event detection

10. How to get the infomation of an instance in multi instances?

11. Multiple program instances

12. just one instance of win95 app?

 

 
Powered by phpBB® Forum Software