Last Updated: 11 Feb 2015 15:18 by ADMIN
Dess | Tech Support Engineer, Principal
Created on: 29 Dec 2014 07:37
Category: Form
Type: Bug Report
FIX. RadMessageBox - InvalidOperationException when showing a message box after the Application.Exit method is called
To reproduce:

private void radButton1_Click(object sender, EventArgs e)

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    RadMessageBox.Show("Do you want to exit?", "Confirmation", MessageBoxButtons.YesNo);

Workaround: Show the RadMessageBox first and then call the Application.Exit method according to the DialogResult.

When Application.Exit() is called it iterates through all forms and for each of them calls the FormClosing event. Currently the RadMessageBox is shown in a new form. So in this case during the iterating forms collection a new form is added and this causes the exception "Collection was modified; enumeration operation may not execute.". 
This is expected behavior and there are two possible solutions to prevent application from throwing exception: 
- Use this.Close(); to close the application.
- Make your checks, show RadMessageBox and after that, if needed call Application.Exit();