HEJ! Enklast genom att sätta TACKAR!!!Avsluta en tråd i en klass när man stänger av sitt program?
Någon som vet hur man avslutar en tråd i en klass när man stänger av sitt program?
/Alexander
<code>
Public Class Form1
Inherits System.Windows.Forms.Form
Private K1 As New KLASS()
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Public Class KLASS
Private Tråd As New System.Threading.Thread(AddressOf _Tråd)
Public Sub New()
Tråd.Name = "_Tråd"
Console.WriteLine("_Tråd Start")
Tråd.Start()
End Sub
Private Sub _Tråd()
While True
Console.WriteLine("_Tråd kör")
Tråd.Sleep(5000)
End While
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
Console.WriteLine("_Tråd Abort")
Tråd.Abort()
End Sub
End Class
</code>Sv: Avsluta en tråd i en klass när man stänger av sitt program?
Tråd.IsBackground = True
i KLASS konstruktorn.
MSSv: Avsluta en tråd i en klass när man stänger av sitt program?
Att det kan vara så enkelt ibland...när man vet hur det är...