I have been playing around with a COM object written in VFP to run Asynchronous requests. The concept is to instanciate a server, call a method that instanciates a timer that runs the real method, and then immediately return control to the caller. The timer does the real work, and sets a "done" flag after the work is done, and then sets its interval to 0, disabling itself. I can't get it to work. The timer event just does not fire. I searched MSDN for documentation on timers running in COM servers, but found nothing.
I could have sworn that I remembered seeing an example of doing something like this, so I went digging, and found the server example that shipped with VFP 5, that implements a pool in VFp using timers. So I compiled my project in VFP 5 and it worked! Did we lose something that I am not aware of? Do timers not work in COM servers any more? On my machine, running the following server as either a single use, multi-use or out of proc server produces no results. No errors, it just doesn't work.
Here is my code, if you want to try it.
DEFINE CLASS maccom AS Custom OLEPUBLIC
Name = "maccom"
tally = .F.
otimer = .F.
Done = .F.
PROCEDURE domethod
LPARA tcMethod
THIS.Done = .F.
THIS.oTimer = CREATEOBJECT("AsynchTimer")
THIS.oTimer.oCaller = THIS
THIS.oTimer.Method = tcMethod
THIS.oTimer.Interval = 100
THIS.oTimer.Enabled = .T.
ENDPROC
PROCEDURE runquery
SET EXCLUSIVE OFF
SET TALK OFF
SET NOTIFY OFF
sele * from h:\issuer, h:\overlap where issuer.id = overlap.issuerid INTO CURSOR Whatever
USE IN Whatever
ENDPROC
PROCEDURE Init
ENDPROC
ENDDEFINE
DEFINE CLASS asynchtimer AS timer
Name = "asynchtimer"
ocaller = .F.
method = .F.
PROCEDURE Timer
=EVAL("THIS.oCaller" + "." + THIS.Method + "()")
THIS.oCaller.Done = .T.
THIS.Interval = 0
THIS.oCaller = .NULL.
ENDPROC
ENDDEFINE
Then to test, use the following in the command window:
oCOM = CREATEOBJECT("MacCOM")
oCOM.DoMethod("RunQuery")
?oCom.Done
you can tell it didn't run because subsequent check of oCom.Done never return .T.
Erik Moore
Clientelligence