0

I've created a WebAPI webservice that accepts requests from a legacy Visual FoxPro system. The service needs to parse the request and then launch the VFP runtime in order to execute some legacy FoxPro code to actually "process" the request.

I have some code like this:

try{
    foxApp = new VisualFoxpro.FoxApplication();
    foxApp.DoCmd(@"do hqinit with .T.");
    ...
    foxApp.DoCmd("close all");
    foxApp.DoCmd("release all");
    foxApp.Quit();
}
catch{
        ...
}

The foxApp.Quit() constantly throws and error and the FoxPro Application is still left running (I can see it in the Task Manager).

Based on this SO post, I tried the following:

try{
    foxApp = new VisualFoxpro.FoxApplication();
    ...

    while(System.Runtime.InteropServices.Marshal.ReleaseComObject(foxApp) > 0) {}

However, while I no longer get the error I was getting when trying to foxApp.Quit(), VFP Application is still left running after each call to the web service.

How do I ensure that VFP gets closed down at the end of each web request?

Update

I just tested again and realized that the first code block does NOT throw an error. Rather, it simply hangs the server. However, if I add foxApp.DoCmd("clear all") before foxApp.Quit() I get an error stating that:

Cannot clear the object OPANEBROWSER because it is in use.

None of my code references an OPANEBROWSER object some I'm not sure where that is coming from.

Community
  • 1
  • 1
RHarris
  • 10,641
  • 13
  • 59
  • 103
  • That solution must be called after Quit, it only releases the COM object, does not destroy the process. What error yields the Quit call? – Gusman Apr 27 '17 at 22:04
  • Please see my update – RHarris Apr 27 '17 at 22:30
  • try with "clear events" before "release all" and add the "clear all" just before the Quit. – Gusman Apr 27 '17 at 22:33
  • 1
    Which version of VFP are you using? I just tested with 8.0 (all I had quick access to) and your code worked fine--sans the "do hqinit" part and no problem when I hit the Quit command. Maybe there are some auxiliary files missing? I'll try in VFP9 (SP1, I think) and see what happens... – Steve Apr 27 '17 at 23:12
  • Thanks, I'm using VFP9 SP2 – RHarris Apr 28 '17 at 12:14

1 Answers1

1

Got it!

I had installed VFP9.0 SP2 on the server and technically, I'm launching the app itself. On my dev environments, I always disable the Task Manager pane that MS pops up by default. However, I had not done that on the server VFP environment.

Once I disabled the Task Manager in VFP environment so that it did not get displayed on Start of VFP, everything was golden.

RHarris
  • 10,641
  • 13
  • 59
  • 103
  • Oh yeah. I forget about the Task manager getting in the way of stuff like this (I always disable it the first thing I do after I install VFP and it's been a while since I've installed it!). Glad that solved your problem! – Steve Apr 28 '17 at 15:39