Important: The information in this document is obsolete and should not be used for new development.
Dealing With Timeouts
When your application callsAESend
and chooses to wait for the server application to handle the Apple event, it can also specify the maximum amount of time it is willing to wait for a response. You can specify a timeout value in thetimeOutInTicks
parameter toAESend
. You can either specify a particular length of time, in ticks, that your application is willing to wait, or you can specify thekNoTimeOut
constant or thekAEDefaultTimeout
constant.Use the
kNoTimeOut
constant to indicate that your application is willing to wait forever for a response from the server. You should use this value only if you are sure that the server will respond in a reasonable amount of time. You should also implement a method of checking whether the user wants to cancel. The idle function that you specify as a parameter toAESend
should check the event queue for any instances of Command-period and immediately returnTRUE
as its function result if it finds a request to cancel in the event queue.Use the
kAEDefaultTimeout
constant if you want the Apple Event Manager to use a default timeout value. The Apple Event Manager uses a timeout value of about one minute if you specify this constant.If you set the
kAEWaitReply
flag and the server doesn't have a handler for the Apple event, the server immediately returns theerrAEEventNotHandled
result code. If the server doesn't respond within the length of time specified by the timeout value,AESend
returns theerrAETimeout
result code and a reply Apple event that contains no data. This result code does not necessarily mean that the server failed to perform the requested action; it means only that the server did not complete processing within the specified time. The server might still be processing the Apple event, and it might still send a reply.If the server finishes processing the Apple event sometime after the time specified in the
keyTimeoutAttr
attribute has expired, it returns a reply Apple event toAEProcessAppleEvent
. The Apple Event Manager then adds the actual data to the reply. Thus, your application can continue to check the reply Apple event to see if the server has responded, even after the time expires. If the server has not yet sent the reply when the client attempts to extract data from the reply Apple event, the Apple Event Manager functions return theerrAEReplyNotArrived
result code. After the reply Apple event returns from the server, the client can extract the data in the reply.Additionally, the server can examine the
keyTimeoutAttr
attribute of the Apple event to determine the timeout value specified by the client. You can use the value of this attribute as a rough estimate of how much time your handler has to respond. You can assume that your handler has less time to respond than the timeout value, because transmitting the Apple event uses some of the available time, as does transmitting the reply Apple event back to the client, and the event may have been in the queue for a while already.If you set the
kAENoReply
orkAEQueueReply
flag, the Apple Event Manager ignores any timeout value you specify, because your application is not waiting for the reply. An attempt by the server to examine thekeyTimeoutAttr
attribute in this situation generates the errorerrAEDescNotFound
.If your handler needs more time than is specified in the
keyTimeoutAttr
attribute, you can reset the timer by using theAEResetTimer
function. This function resets the timeout value of an Apple event to its starting value.