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

Application.ThreadException not fire when raise exception in ContextMenuStrip.Closed event.

$
0
0

program.cs

    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.ThreadException += Application_ThreadException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.ToString());
        }
    }

Form1.cs

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.ContextMenuStrip = contextMenuStrip1;
        }

        private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)
        {   
            throw new Exception("Closed Exception");
        }
    }

1. Build and Run (Ctrl + F5).

2. Mouse right button click on Form.

3. Show ContextMenu and Form Click (not ContextMenu).

4. Raise unhandled event and application kill.

Why not fire Application.ThreadException event?

But.

3. Show ContextMenu and ContextMenuItem Click

4. Fire Application.ThreadException event and keep appliation.



Viewing all articles
Browse latest Browse all 8156


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