Omnis Technical Note TNWE0012

Cancelling a long server process in a remote form.

For Omnis Studio 4.x or above
By Omnis Tech Support

This tech note outlines a technique that can be used to implement a Cancel button on a remote form that allows the end user to cancel or abort a long server process. It uses the $alwaysenabledobject property.

Normally when an event on a remote form executes and the server is called, a working message is shown on the client and all controls on the remote form are disabled until the call to the server is complete and the server has responded, at which point, all objects on the remote form are enabled again. This is done to prevent multiple calls to the server as the client can only send one event at a time.

However you can implement a Cancel button that is never disabled that the end user can click on to cancel a long server process. You can set such a button to be 'always enabled' using the $alwaysenabledobject property of the button. So even when you have kicked off a big operation that will go back and forth to the server a lot, the user can click on the Cancel button and abort the server process.

For example, if you are sending a list of documents to the server, you could implement the following method.

1. Click to start
2. for x = 1 to enddoc
3.   send doc to server ( wait for reply )
4.   next doc
5. end for

Having a Cancel button always enabled allows the button to set a flag to cancel the loop:

1. Click to start
2. for x = 1 to enddoc
3.   test if cancel was pressed - if so, stop loop
4.   send doc to server ( wait for reply )
5.   next doc
6. end for