It is important to remember that events simply provide information on the state or activities taking place within AutoCAD. Although event handlers can be written to respond to those events, AutoCAD is often in the middle of processing commands when the event handler is triggered. Event handlers, therefore, have some restrictions on what they can do if they are to provide safe operations in conjunction with AutoCAD and its database.
When writing event handlers, do not rely on the sequence of events to happen in the exact order you think they occur. For example, if you issue an OPEN command, the events BeginCommand, BeginOpen, EndOpen, and EndCommand will all be triggered. However, they may not occur in that order. The only event sequence you can safely rely on is that a Begin event will occur before the corresponding End event. In the previous example, the events may get triggered in the following order: BeginCommand, BeginOpen, EndCommand, and EndOpen, or even BeginCommand, EndCommand, BeginOpen, and EndOpen.
If you delete object1 and then object2, do not rely on the fact that you will receive the ObjectErased event for object1 and then for object2. You may receive the ObjectErased event for object2 first.
Attempting to execute interactive functions from within an event handler can cause serious problems, as AutoCAD may still be processing a command at the time the event is triggered. Therefore, you should always avoid the use of input-acquisition methods such as GetPoint, GetEntity, GetKeyword, and so on, as well as selection set operations and the SendCommand method from within event handlers.
Dialog boxes are considered interactive functions and can interfere with the current operation of AutoCAD. Message boxes and alert boxes are not considered interactive and can be issued safely; however issuing a message box within an event handler for the BeginModal, EndModal, Activate, Deactivate, and BeginRightClick events results in unexpected sequencing.
Obviously, any object causing an event to be triggered could still be open for use with AutoCAD and the operation currently in progress. Therefore, avoid writing any information to an object from an event handler for the same object. However, you can safely read information from the object triggering an event. For example, suppose you have a floor that is filled with tiles and you create an event handler attached to the border of the floor. If you change the size of the floor, the event handler will automatically add or subtract tiles to fill the new area. The event handler will be able to read the new area of the border, but it cannot attempt any changes on the border itself.
If you perform the same action in an event handler that triggers that same event, you will create an infinite loop. For example, you should never attempt to open a drawing from within the BeginOpen event, or AutoCAD will simply continue to open more drawings until the maximum number of open drawings is reached.