Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Feedback
Message
 
To
07/06/2004 09:30:51
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00910724
Message ID:
00910725
Views:
29
This message has been marked as the solution to the initial question of the thread.
Try this on:
&& 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

&& client testprogram
startprocess.prg:

PUBLIC loFoxServer, loEventhandler

loFoxServer = CREATEOBJECT('testcom1.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 .. 

&& simulate block situation
DECLARE INTEGER Sleep IN WIN32API INTEGER
Sleep(15000) && the event of ther server is fired when this runs


endprocess.prg:

loFoxServer.Unadvise()
loFoxServer = NULL
loEventhandler = NULL
>I am searching for ideas on how to give feedback to the user while a long process is under way. The user sets all the treatments he would like to do on a file and click on the "Process" button. The click event of the button calls the Process method of my COM object. The GUI is now frozen there until my COM return and the COM return only when all the treatments are done, witch can take many minutes.
>
>How do I give feedback to the user on the process of the treatments? I cannot start a new thread because VFP is not multi-threaded, the GUI is stuck to the call to the COM and AFAIK, the COM should not display anything on screen because it may be ported to the internet in a near future.
>
>Any ideas?
>
>TIA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform