Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multithreading VFP
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00909234
Message ID:
00910779
Vues:
17
Nick, needless to say VFP mtdlls will accomplish this with no problem. However, if you must use VFP COM EXEs, you could try CallBack and FireEvents - we were actually discussing this in another thread. This is basically the Pooling example that was in some old VFP versions:
&& server objects (compile into COM-Exe)

DEFINE CLASS oTestServer AS Session OLEPUBLIC

    loCallback = .NULL. && saves reference to callback object
    lAdvised = .F. && is callbackobject set?
    HIDDEN loTimer

    FUNCTION Init
	DECLARE INTEGER Sleep IN WIN32API INTEGER		
	THIS.loTimer = CREATEOBJECT('dirTimer',THIS)
    ENDFUNC

    FUNCTION Destroy
	THIS.loTimer = NULL
	CLEAR DLLS	
   ENDFUNC

   FUNCTION FireEvent AS VOID
      LPARAMETERS lcSomeValue
      IF THIS.lAdvised
         THIS.loCallBack.EventMethod(lcSomeValue)
      ENDIF
   ENDFUNC

   FUNCTION Advise AS VOID
      LPARAMETERS loObj
      THIS.loCallback = loObj
      THIS.lAdvised = .T.
   ENDFUNC

   FUNCTION UnAdvise AS VOID
      THIS.loCallback = .NULL.
      THIS.lAdvised = .F.
   ENDFUNC

   FUNCTION SomeMethodThatFiresEvents AS Boolean
        && prepare something
        THIS.FireEvent('Task startet .. ')
        Sleep(5000)
        THIS.FireEvent('Task finished X percent ..')
        Sleep(5000)
        && do more
        THIS.FireEvent('Task fineshied XX percent ..')
        && ..
    ENDFUNC

    FUNCTION DoSomeAsynWork AS Boolean
    	THIS.loTimer.Interval = 1
	RETURN .T.
    ENDFUNC

ENDDEFINE

DEFINE CLASS dirTimer AS Timer

	Interval = 0
	loParent = NULL

	FUNCTION Init
		LPARAMETERS loObj
		THIS.loParent = loObj
	ENDFUNC

	FUNCTION Destroy
		THIS.loParent = NULL
	ENDFUNC

	FUNCTION Timer
		THIS.Interval = 0
                && do some work
                Sleep(1000) && sleep to simulate some work ..
		THIS.loParent.FireEvent('Timer Fired')
	ENDFUNC

ENDDEFINE
and
*startprocess.prg:
PUBLIC loFoxServer, loEventhandler

loFoxServer = CREATEOBJECT('testserver.oTestServer')
loEventHandler = CREATEOBJECT('oTestCallback')

loFoxServer.Advise(loEventHandler)

DEFINE CLASS oTestCallback AS Session OLEPUBLIC

    FUNCTION EventMethod
        LPARAMETERS lcSomeParam
        ? lcSomeParam
    ENDFUNC

ENDDEFINE
and
*startasyn.prg:
?loFoxServer.DoSomeAsynWork() && returns immediately .. 
?loFoxServer.SomeMethodThatFiresEvents()
&& simulate block situation
DECLARE INTEGER Sleep IN WIN32API INTEGER
*Sleep(15000) && the event of ther server is fired when this runs
and
*endprocess.prg:
loFoxServer.Unadvise()
loFoxServer = NULL
loEventhandler = NULL
>>>Claude:
>>What type of application are you trying to create?
>
>I am trying to Multithread VFP from VFP, probably in seperate processes.
>
>It is so that our Webserver can have a pool of worker processes and dish out each request to a process from that pool. This is to ensure that no single request can block all the others.
>
>Nick
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform