Cannot quit Visual FoxPro

The 'Cannot Quit Visual FoxPro' message must be one of the most common problems you meet when starting to work with Visual FoxPro.

It has been with us since the launch of Visual FoxPro but the problem still causes difficulties. The error message does not give an error number so you cannot find it in the Help system. Help returns nothing if you search for 'Cannot Quit Visual FoxPro' and MSDN is equally unhelpful. A search on Google though will show you that it's a very common question in all the support forums so it's disappointing that Microsoft have not added it to Help.

Especially as it is a very simple problem to fix.

Close the application

The first thing to do is to close the application that has locked. The least damaging way of doing this is to use the Windows Task Manager. In Windows 2000 and Windows XP you can open the Task Manager by pressing Ctrl+Alt+Del or by right-clicking on the Windows status bar. Select Task Manager from the options that appear then click the Applications on the Task Manager dialog:

[Windows Task Manager]

Select your Visual FoxPro application from the list then click the End task button. You will be warned that this is an extreme act and asked to confirm that you do indeed want to cancel this process. Click OK and wait. Windows may take several seconds to complete the task of closing down the application. When it has been closed you will be told that you have terminated FoxPro prematurely and asked whether you want to report the problem to Microsoft. We have been reporting this for ten years now so I suspect it will be a waste of time to report it again.

Now that you have cancelled the application, close the Task Manager and open your project in FoxPro.

Solution

The problem arises because Visual FoxPro is event-driven. The RunTime engine opens your executable and then responds to events as they occur. You have closed your application but not told FoxPro to stop waiting for events.

The command to stop the event-processing loop is:

Clear Events

and FoxPro must execute this command whichever way that the application closes down. Depending on the structure of your application you might put the command is several different places:

  • In the procedure called by the Quit option on the File menu.
  • In the Click event of the button that closes your main form.
  • When the application shuts down:
    On Shutdown Clear Events

FoxPro executable flashes on screen and vanishes

The other problem you'll hit with the FoxPro event-processing loop is when you find that your executable won't run outside of the development environment. You just see a flash of your main form on screen before the executable closes. More details here .

Access Tips

FoxPro Tips

General Tips

 

Related Items

Distributing a VFP 8 executable

Distributing the executable and support files for a Visual FoxPro application

Read More

FoxPro form flashes on the screen and vanishes

VFP executable flashes on the screen and vanishes

Read More

Visual FoxPro Tutorial - Build an executable

Visual FoxPro Tutorial - Build a Windows executable from a Foxpro project

Read More