Undo from modeless ETO

I am developing a tool using ETO forms. In case of modeless ETO forms, how can I undo the latest command? On applying ctrl + z it removes the last command from rhino window, while the commands implemented from modeless ETO form remains intact.

I think before you run a command from your window, you should call doc.BeginUndoRecord and on completion run doc.EndUndoRecord

RhinoDoc doc; // reference to the active document
uint undoRecordNumber = doc.BeginUndoRecord("Command from Eto");
RhinApp.RunScript(...); // execute command
if (!doc.EndUndoRecord(undoRecordNumber))
{
  //something is wrong
}

See
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_RhinoDoc_BeginUndoRecord.htm