Wie zu verwenden ThreadException?

Versuchte ich mit

http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx#Y399

aber wenn ich das mache

throw new ArgumentNullException("playlist is empty");

Bekomme ich nichts. Ich Wette, ich bin fehlt etwas sehr offensichtlich.

hier ist mein code.

using System;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Threading;

namespace MediaPlayer.NET
{
    internal static class Program
    {
        ///<summary>
        ///The main entry point for the application.
        ///</summary>
        [STAThread]
        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
        private static void Main()
        {
            //Add the event handler for handling UI thread exceptions to the event.
            Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);

            //Set the unhandled exception mode to force all Windows Forms errors to go through
            //our handler.
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            //Add the event handler for handling non-UI thread exceptions to the event. 
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(UnhandledException);

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

        private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show("UnhandledException!!!!");
        }

        private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
        {
            MessageBox.Show("UIThreadException!!!!",
                            "UIThreadException!!!!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
            Application.Exit();
        }
    }
}
  • die Linie [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)] ist nötig für die Handhabung von Ausnahmen, die Erzeugung von threads auf?
InformationsquelleAutor IAdapter | 2011-02-01
Schreibe einen Kommentar