Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running VFP application as a service
Message
 
 
To
26/11/2005 17:20:15
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01070719
Message ID:
01072224
Views:
67
>
>Actually in my sample (message #1071516) I tried to resemble what I understood about Calvin's example (a simple timer loop doing something - "The code executes the timer event every 5 seconds, aligned to the 5 second real time clock (so that it occurs at exactly :00, :05, :10, … seconds past the hour).").
>
>To be honest with you I couldn't follow the part bellow ("The sample service code below executes a file called “vfpsrvrtn.prg” when the timer fires. However, this code is not built into the EXE. This means you can change the service’s behavior dynamically, without having to stop/rebuild/start the service">):

<snip>

Here's the code from my VFPService project main program
LPARAMETERS parm1, parm2

#define TIMERINT  5     && # of seconds for timer interval. 
                        &&Also syncs to TIMERINT seconds for time of day
PUBLIC oService
oService=NEWOBJECT("vfpsrv")
oService.logstr("Starting Service: got some params: "+TRANSFORM(parm1)+" "+TRANSFORM(parm2))
IF _vfp.StartMode>0     && if we’re running as an EXE
      READ events       && message loop
ENDIF

RETURN

DEFINE CLASS vfpsrv AS form

      PROCEDURE Init
            this.logstr(FULLPATH(""))
            DECLARE integer MessageBeep IN WIN32API integer
            this.AddObject("mytimer","mytimer")
            WITH this.mytimer
                  .enabled=.t.
                  .interval=1000    && start it in a sec
            ENDWITH

      PROCEDURE Destroy
            ?PROGRAM()
            MessageBeep(32)

      PROCEDURE logstr(str as String)
            str=TRANSFORM(DATETIME())+" "+str+CHR(13)+CHR(10)
            ??str
            STRTOFILE(str, "h:\tmp\vfpsrv.log",.t.)

ENDDEFINE

DEFINE CLASS mytimer AS timer
      PROCEDURE timer
            DO ("vfpsrvrtn" ) with this, oService
            CLEAR PROGRAM
            dtNow=DATETIME()  && read datetime() and seconds() close to the same instant
            nsec=SECONDS()
            nsec=CEILING((nsec+.5)/TIMERINT)*TIMERINT 
            dtTarget=DTOT(DATE())+nsec
            this.interval=(dtTarget-dtNow) * 1000

ENDDEFINE
And here is the code for vfpsrvrtn.prg
LPARAMETERS oTimer,oService
oService.logstr(PROGRAM())
Messagebeep(0)
>Anyway there is an obscure part (parameter passing) that was a bit hard to figure out when registering the service (registry and instsrv). We found elsewhere instsrvw.exe that found a lot less cumbersome.
> Just by using
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VFPSrv\Parameters]
"AppDirectory"="d:\\fox90\\test" 
"Application"="d:\\fox90\\test\\vfpsrv.exe" 
"AppParameters"="myparm1 myparm2"
actually didn't work.


It works for me if I copy .REG file exactly as in the Calvins's blog ( see above).

>I can't believe that either I'm too naive or that stuff is so hard to work.
>
>If it's not too much to ask, did you try to make my sample work? If so, what is wrong with it?


I didn't try your code because it doesn't make much sense to me. The windows service is run on background w/o GUI and all your code relies on GUI presented. If you want to run it with GUI why bother with turning it into a service?
My suggestion stays. Get Calvin's code to work, understand it and move from there.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform