#region "send Zoom command by callback function"
private static bool ZoomExit = false;
//declare the callback delegation
delegate void Del();
private static Del _actionCompletedDelegate;
// Exit function,check if Zoom command is esc\cancelled
static void
MdiActiveDocument_CommandCancelled(object sender,CommandEventArgs e)
{
ZoomExit = true;
}
[CommandMethod("TestZoom")]
public static void TestZoom()
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
var doc = Application.DocumentManager.MdiActiveDocument;
//esc event
doc.CommandCancelled += MdiActiveDocument_CommandCancelled;
// start Zoom command
Editor.CommandResult cmdResult1 =
ed.CommandAsync(new object[]{
"_.ZOOM", Editor.PauseToken, Editor.PauseToken});
// delegate callback function, wait for interaction ends
_actionCompletedDelegate = new Del(CreateZoomAsyncCallback);
cmdResult1.OnCompleted(new Action(_actionCompletedDelegate));
ZoomExit = false;
}
// callback function
public static void CreateZoomAsyncCallback()
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
//if Zoom command is running
if (!ZoomExit)
{
// AutoCAD hands over to the callback function
Editor.CommandResult cmdResult1 =
ed.CommandAsync(new object[]{
"_.ZOOM", Editor.PauseToken, Editor.PauseToken});
// delegate callback function, wait for interaction ends
_actionCompletedDelegate = new Del(CreateZoomAsyncCallback);
cmdResult1.OnCompleted(new Action(_actionCompletedDelegate));
}
else
{
ed.WriteMessage("Zoom Exit");
return;
}
}