Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MSMQ implementation
Message
 
À
01/01/2005 13:36:18
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
00973622
Message ID:
00973643
Vues:
39
This message has been marked as the solution to the initial question of the thread.
I have a TestServerClass project that contains the class with the timer - compiled into a COM EXE. Next, you should have a startprocess.prg - start that. Next there is a startasyn.prg - fire that off. What you will see are background updates happening while you're free to do other things in VFP(in the command window fpr example). Start endprocess.prg to kill it.
Here are the sources broken out:
*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
*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

FOR F = 1 TO 20
? F
*doevents && sleep(0) is better
sleep(500)
ENDFOR
*endprocess.prg:

loFoxServer.Unadvise()
loFoxServer = NULL
loEventhandler = NULL
*testserverclass.prg
&& 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
                THIS.loParent.SomeMethodThatFiresEvents() &&test
                Sleep(1000) && sleep to simulate some work ..
		THIS.loParent.FireEvent('Timer Fired')
	ENDFUNC

ENDDEFINE
>HI Claude,
>
>Sometime back I tried this. See thread = 054922
>
>Sadlu, I never did "get it".
>
>It does sound (in some ways) like a simpler to implement solution.
>
>I've been writing fox for 10+ years and working 100 hours a week for years. It seems this would be easy but I know so little.
>
>The code you posted. Do I understand?:
>
>The first part that starts DEFINE CLASS oTestServer, Do I create a VFP project and place this code somewhere in that project? I have no idea where.
>
>StartProcess.PRG: Is this a program that I just create and run from the command window?
>
>StartAsyn.PRG: When and where do I run this program?
>
>Thanks,
>John
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform