You cannot alter an enumeration while iterating over it.
You can create a temporary collection of matching forms and then iterate over that collection and close them:
public void CloseAllOpenForm( Form currentForm )
{
var list = new List<Form>();
foreach ( Form form in Application.OpenForms )
if ( !currentForm.Equals( form ) )
list.Add( form );
foreach ( Form form in list )
form.Close();
}
Nick