How to Abort an ADE Computation



Various ADE methods such as these may result in long computations times:

(Several other methods could launch length computation in certain more unusual circumstances, including CAEngine::OpenModel, CAObject::DefTable, and others).

Once your program makes the call to any of these methods, it is stuck waiting until the method call returns. If the model contains an extremely length computation, or even an infinite loop, you may want to provide the users of your program with a method for aborting the computation, similiar to Analytica's Ctrl+Break handling.

To do this, you will need to have another thread running in your program which can receive the Ctrl+Break request. You can't use the thread that has called ADE for this purpose, since it is humbling waiting for the method call to return!

Before making the method call, your program must first ask ADE for the identifier of a global Event object which it creates, and you will use, to send the abort event. You obtain this object via a call to GetProcessInfo("Abort Event Object"), which you will do using CAEngine::SendCommand. Your application then uses this name to get an Event Handle from the Windows operating system, and uses the SetEvent system call to signal that the ADE computation currently in progress should abort.

Using Windows Native API

If you are using Window's native API, this looks like this (e.g., C++):

string gEventId; // A global used to hold the event name

On the main calling thread:

 // You only have to do this part once, e.g., immediately after creating the ADE instance.
 pAde->SendCommand("GetProcessInfo('Abort Event Object')");
 gEventId = ade->OutputBuffer;
 ...
 com_ptr_t<CAObject> pObj = pAde->Get("Some_result");
 com_ptr_t<CATable> pRes = pObj->ResultTable();   // this sits and waits...

On the other thread:

 // when abort request received:
 HANDLE hAbort = CreateEventEx(/*sam*/NULL, gEventId, 0, EVENT_MODIFY_STATE);
 SetEvent(hAbort);

Using .NET

Need to fill in

See Also

Comments


You are not allowed to post comments.