IR
irwinrodriguez.dev

Included in FoxCli

FoxService

Windows services written in Visual FoxPro.

Do you have a PC with a VFP exe and a Timer that somebody has to leave open to import orders, send the pending emails or run the closing of every night? FoxService turns it into a Windows service: it starts with the computer, keeps running even if nobody logs in, comes back up if it falls and writes to the Event Log. You only write the logic, in VFP.

It comes with FoxCli

FoxService is part of the FoxCli installer and license: it is not bought separately. Without a license it runs in full, without limits, and the service says when it starts that it is in evaluation.

See the FoxCli license →

How you write it

A class in src\main.prg, and every public method is a job. The *!* line above it says when it runs. It is the sample every new project comes with: an importer of orders that already works the first time you run it.

Three jobs of a service: when a file arrives, every 30 seconds and every night
DEFINE CLASS OrdersService AS FoxServiceBase OF foxservice.prg OLEPUBLIC

    *-- Every CSV that arrives in inbox\: its orders into the table.
    *!* @watch inbox *.csv
    PROCEDURE ImportOrders(tcPath, tcChange)
        ...
    ENDPROC

    *-- Every 30 seconds: how many orders are waiting.
    *!* @every 30s
    PROCEDURE CountPending
        LOCAL lnPending
        THIS.OpenOrders()
        COUNT FOR status == "P" TO lnPending
        THIS.Log("Pending orders: " + TRANSFORM(lnPending))
    ENDPROC

    *-- Every night: the summary of the day.
    *!* @daily 23:55
    PROCEDURE DailySummary
        THIS.WriteSummary()
    ENDPROC

ENDDEFINE

When each job runs

*!* @every 30s
Every so often, in seconds, minutes or hours. A change of the system clock does not move it.
*!* @daily 04:00
At a time of day, in 24-hour format and at the time of the computer, daylight saving included. Several lines, several times.
*!* @startup
Once, when the service starts: preparing tables, checking folders.
*!* @watch inbox *.csv
Every file that arrives in a folder. The service waits until it has been copied, and the ones already there at startup are delivered too.
(no *!* line)
A manual job: it does not run by itself, and you run it whenever you want, from FoxForge or with "invoke".

All from the VFP IDE

From the console, or from an agent

The foxservice CLI does the same without the IDE, and on the server the service's exe is enough. Its commands are also tools for an AI agent (foxservice_new, foxservice_build, foxservice_install…) through FoxStack, for free.

foxservice new --name orders --folder C:\svc
foxservice build --folder C:\svc\orders
foxservice run --folder C:\svc\orders --for 1m
orders.exe install --account "NT SERVICE\orders" --start

What does not fit in a service

A service has no screen and no user: no forms, no MESSAGEBOX, no printing to a printer. Code that tries does not hang: the job fails at once, and the log says the line and the reason. A VFP error reaches the log by itself, with its number and its line, and the service keeps running, so jobs are written without TRY ... CATCH.

What it needs

To program, Visual FoxPro 9 or 32-bit VFP Advanced 10.2, and FoxForge, which is installed with FoxCli. On the server, Windows with the 32-bit .NET 10 runtime: no Visual FoxPro, because its runtime travels in the service's folder, and no license, because the license belongs to whoever builds.

The guide

The full guide comes with FoxForge, in Help > FoxService guide, in English, Spanish and German. It starts with the first steps: the importer of orders, explained job by job.

Frequently asked questions

Do I need to know .NET or Windows?

No. You write a VFP class. The service's exe, which FoxService leaves in the dist\ folder next to your DLL, takes care of installing, starting and stopping it, of the schedules and of the Event Log. From FoxForge you do not even need to open a console: Install, Start and Stop are buttons.

How is it different from FoxServer and FoxCore?

FoxServer answers HTTP requests: somebody calls and your code answers. FoxCore runs tasks in the background inside your application, so that its screen does not freeze meanwhile. FoxService needs no application open: it works on its own, when its time comes, at a time of day, every so often or when a file arrives. They can be used together, each one with its license.

Which license do I need?

The FoxCli one: FoxService comes with it and with its installer. The license belongs to whoever builds; the servers where the service runs need none. Without a license everything runs, without limits, and the service says once when it starts that it is in evaluation.

Which Windows account does it run as?

The one it comes with is the system account (LocalSystem): it reaches any folder of the computer, like the desktop program it replaces. For a network folder, an account of the service's own (NT SERVICE\name) or a Windows or domain user; the password is asked for when installing, without echo.

What are the "jobs at the same time"?

With 1, the value it comes with, jobs queue up: if an import takes ten minutes, the one that runs every 30 seconds waits and its turns are skipped meanwhile. With 2 or more, a long job does not delay the short ones. Each one is a separate VFP, with its variables and its open tables.

What happens if a job fails or hangs?

A VFP error reaches the log with its number and its line, the job counts as failed and the service goes on. A job that goes past its maximum time (one hour, unless you say otherwise) is told to stop; if it does not come back, the service restarts itself within seconds. Three times in a row, and that job is no longer scheduled until you look at it.

Can I print?

To a printer, no: a service has no user session and no printers. The job that tries fails at once, and the log says so.

And make a report as a PDF?

Yes, with the reports runtime: ReportToPdf takes the pages of an .frx and the service composes the PDF. The pages are images at 300 dpi, so the text cannot be selected or searched, and with that runtime one job runs at a time.

Does it work with VFP Advanced?

Yes, with 32-bit VFP Advanced 10.2. Two differences: there is no reports runtime, and it stays at one job at a time.

Can an AI agent create and install the service?

Yes. The commands of the foxservice CLI are MCP tools through FoxStack, for free. Installing needs an administrator console: if the agent does not have one, it gets the exact command for a person to run.

If something does not add up, write to me: soporte@irwinrodriguez.dev