Performing Lengthy Operations

Windows 95 and Windows NT use preemptive multitasking. This means that the operating system determines when an application must give up the processor so that other applications can run. Even though the operating system can preempt Microsoft Excel it is still a good idea to give up the processor during long tasks. Normally, Microsoft Excel gives up the processor frequently, allowing background tasks to run smoothly.

If you expect your DLL function to take a long time, you will need to:

There is a single function called xlAbort that handles both of these tasks at once. First it yields, giving other applications in the system a chance to run. Then it checks whether the user has canceled by pressing ESC. If so, xlAbort returns TRUE; if not, it returns FALSE.

When the user cancels the function by pressing ESC, the DLL should clean up and return as quickly as possible. However, you might want to prompt the user to confirm the cancellation, offering the option of continuing. If the user wants to continue, the pending cancellation can be cleared by calling xlAbort with one argument, an xltypeBool with the value FALSE.

For an example of the xlAbort function, see the fDance function in GENERIC.C in the FRAMEWRK directory.