Imports System.Threading Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows フォーム デザイナで生成されたコード " Public Sub New() MyBase.New() ' この呼び出しは Windows フォーム デザイナで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後に初期化を追加します。 End Sub ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。 'Windows フォーム デザイナを使って変更してください。 ' コード エディタを使って変更しないでください。 Friend WithEvents button1 As System.Windows.Forms.Button Friend WithEvents button2 As System.Windows.Forms.Button Private Sub InitializeComponent() Me.button1 = New System.Windows.Forms.Button Me.button2 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'button1 ' Me.button1.Location = New System.Drawing.Point(32, 24) Me.button1.Name = "button1" Me.button1.Size = New System.Drawing.Size(232, 23) Me.button1.TabIndex = 2 Me.button1.Text = "Application_ThreadException例外" ' 'button2 ' Me.button2.Location = New System.Drawing.Point(32, 72) Me.button2.Name = "button2" Me.button2.Size = New System.Drawing.Size(232, 23) Me.button2.TabIndex = 1 Me.button2.Text = "Application_UnhandledException例外" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12) Me.ClientSize = New System.Drawing.Size(292, 126) Me.Controls.Add(Me.button1) Me.Controls.Add(Me.button2) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click ' メイン・アプリケーション・スレッドで発生した例外 Me.Parent = Me End Sub Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click Dim errorThread As New Thread(New ThreadStart(AddressOf ErrorThreadMethod)) errorThread.Start() End Sub ' 別スレッドで発生した例外 Private Shared Sub ErrorThreadMethod() Dim buffer As String = "1" Dim [error] As Char = buffer.Chars(2) End Sub End Class