if you want to close all currently existing modal dialogs, do it in a loop. For example:
var Core::Root root = GetRoot();
var Core::Group modalGroup = root.GetModalGroup();
while ( modalGroup != null )
// Remove the dialog from its owner.
modalGroup.Owner.Remove( modalGroup );
// ... and end the modal state for this group
root.EndModal( modalGroup );
// Get the next modal group from the modal stack
modalGroup = root.GetModalGroup();
Similarly, you can close several nested dialogs until you reach one particular stop dialog. You need to know the stop dialog and then you can test in the loop whether the dialog has been reached:
var Core::Group groupToStop = ...
while (( modalGroup != null ) && ( modalGroup != groupToStop ))
Does it help you further?