Difference between revisions of "How to Abort an ADE Computation"

 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
[[Category: Analytica Decision Engine]]
 +
 +
__TOC__
 +
 +
 
Various ADE methods such as these may result in long computations times:
 
Various ADE methods such as these may result in long computations times:
 
* [[CAEngine::Send]]
 
* [[CAEngine::Send]]
Line 13: Line 18:
 
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!
 
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 <code>[[GetProcessInfo]]("Abort Event Object")</code>, 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.
+
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 <code>GetProcessInfo("Abort Event Object")</code>, 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 =
+
== Using Windows Native API ==
  
 
If you are using Window's native API, this looks like this (e.g., C++):
 
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
+
:<code>string gEventId;  // A global used to hold the event name</code>
 
   
 
   
 
On the main calling thread:
 
On the main calling thread:
 +
<pre style="background:white; border:white; margin-left: 1em;">
 +
// You only have to do this part once, e.g., immediately after creating the ADE instance.
 
  pAde->SendCommand("GetProcessInfo('Abort Event Object')");
 
  pAde->SendCommand("GetProcessInfo('Abort Event Object')");
 
  gEventId = ade->OutputBuffer;
 
  gEventId = ade->OutputBuffer;
 
  ...
 
  ...
 
  com_ptr_t<CAObject> pObj = pAde->Get("Some_result");
 
  com_ptr_t<CAObject> pObj = pAde->Get("Some_result");
  com_ptr_t<CATable> pRes = pObj->ResultTable();  ''// this sits and waits...''
+
  com_ptr_t<CATable> pRes = pObj->ResultTable();  // this sits and waits...
 +
</pre>
  
 
On the other thread:
 
On the other thread:
 +
<pre style="background:white; border:white; margin-left: 1em;">
 
  // when abort request received:
 
  // when abort request received:
 
  HANDLE hAbort = CreateEventEx(/*sam*/NULL, gEventId, 0, EVENT_MODIFY_STATE);
 
  HANDLE hAbort = CreateEventEx(/*sam*/NULL, gEventId, 0, EVENT_MODIFY_STATE);
 
  SetEvent(hAbort);
 
  SetEvent(hAbort);
 +
</pre>
  
= Using .NET =
+
== Using .NET ==
  
 
''Need to fill in''
 
''Need to fill in''
 +
 +
== See Also ==
 +
* [[Analytica Decision Engine]]
 +
* [[CAEngine::MethodEvaluationTimeLimit]]
 +
* [[GetProcessInfo]]

Latest revision as of 21:00, 14 March 2016



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.