Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Collection was modified; enumeration operation may not execute

$
0
0

Hi

I am trying to prompt the user before existing the WinForm application. Here is my FormClosing:

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
    if (XtraMessageBox.Show("Are you sure you want to exit now?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
    {
        e.Cancel = true;
    }
}

and then I am using Application.Exit in my btnExit_Click

but I am getting this error:

Collection was modified; enumeration operation may not execute

when the user clicks on btnExit

How can I solve it please..


Viewing all articles
Browse latest Browse all 8156

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>