İngilizce dilinde oku

Aracılığıyla paylaş


ThreadExceptionEventArgs Sınıf

Tanım

ThreadException olayı için veriler sağlar.

C#
public class ThreadExceptionEventArgs : EventArgs
Devralma
ThreadExceptionEventArgs
Türetilmiş

Örnekler

Aşağıdaki örnek, bir ThreadException forma tıklayarak button1 olay oluşturmanızı sağlar. Örnek iki sınıf oluşturur. ErrorHandler sınıfı, olayı tetikleyen formu ve düğmeyi oluşturur. sınıfı, CustomExceptionHandler özel durumu işlemek için yöntemler sağlar.

sınıfında MainErrorHandler kod, özel durum işleme sınıfının yeni bir örneğini, yani örneğini CustomExceptionHandleroluşturur. Ardından örnek olaya eklenir ve uygulama çalıştırılır.

sınıfındaki OnThreadExceptionCustomExceptionHandler yönteminde, örnek özel durumu işlemek için bir try...catch...finally deyimi kullanır. ShowThreadExceptionDialog yöntemi görüntülenecek iletiyi oluşturur ve bir ileti kutusunda görüntüler.

C#
using System;
using System.Threading;
using System.Windows.Forms;

// Create a form with a button that, when clicked, throws an exception.
 public class ErrorForm : System.Windows.Forms.Form
 {
    internal Button button1;

    public ErrorForm() : base()
    {
       // Add the button to the form.
       this.button1 = new System.Windows.Forms.Button();
       this.SuspendLayout();
       this.button1.Location = new System.Drawing.Point(100, 43);
       this.button1.Size = new System.Drawing.Size(75, 23);
       this.button1.Text = "Click!";
       this.Controls.Add(this.button1);
       this.button1.Click += new EventHandler(this.button1_Click);

       this.Text = "ThreadException";
       this.ResumeLayout(false);
    }

    // Throw an exception when the button is clicked.
    private void button1_Click(object sender, System.EventArgs e)
    {
       throw new ArgumentException("The parameter was invalid");
    }

    public static void Main()
    {
       // Add the event handler.
       Application.ThreadException += new ThreadExceptionEventHandler(CustomExceptionHandler.OnThreadException);

       // Start the example.
       Application.Run(new ErrorForm());
    }
 }

 // Create a class to handle the exception event.
 internal class CustomExceptionHandler
 {
     // Handle the exception event
    public static void OnThreadException(object sender, ThreadExceptionEventArgs t)
    {
       DialogResult result = ShowThreadExceptionDialog(t.Exception);

       // Exit the program when the user clicks Abort.
       if (result == DialogResult.Abort)
          Application.Exit();
    }

    // Create and display the error message.
    private static DialogResult ShowThreadExceptionDialog(Exception e)
    {
       string errorMsg = "An error occurred.  Please contact the adminstrator " +
            "with the following information:\n\n";
       errorMsg += string.Format("Exception Type: {0}\n\n", e.GetType().Name);
       errorMsg += "\n\nStack Trace:\n" + e.StackTrace;
       return MessageBox.Show(errorMsg, "Application Error",
            MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
    }
 }

Açıklamalar

İşlenmemiş ThreadExceptionEventArgs bir özel durum oluştuğunda bir iş parçacığı tarafından oluşturulur. ThreadExceptionEventArgs oluşan öğesini Exception içerir.

Oluşturucular

ThreadExceptionEventArgs(Exception)

ThreadExceptionEventArgs sınıfının yeni bir örneğini başlatır.

Özellikler

Exception

Oluşan değeri Exception alır.

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Ayrıca bkz.