Okay, dann werde ich dir mal mein Beispiel von dem Thread posten vielleicht hast du ja eine Ahnung warum VB komplett abschiesst wenn ich command3 drücke.
Wenn ich erst command2 und dann command4 drücke funktioniert es.
Eine Idee?
Fuxs
Option Explicit
Public Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, _
ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, _
ByVal dwCreationFlag As Long, lpThreadId As Long) As Long
Public Declare Function SuspendThread Lib "kernel32" (ByVal hThread As Long) As _
Long
Public Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As _
Long
Public Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As _
Long, ByVal nPriority As Long) As Long
Declare Sub ExitThread Lib "kernel32.dll" (ByVal dwExitCode As Long)
Public Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, _
ByVal dwExitCode As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliSeconds As Long)
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
Long
Public hWatchTh&, WatchThId&
Public Threadbeenden As Boolean
Public Const CREATE_SUSPENDED = &H4
Public Const THREAD_PRIORITY_IDLE = -15
Public Const THREAD_PRIORITY_TIME_CRITICAL = 15
Public Const THREAD_PRIORITY_NORMAL = 0
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) _
As Long
Public Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As _
Long, lpExitCode As Long) As Long
Public Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal x1 As _
Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Public lpExCode As Long
Public Function test_tr(p As Long) As Long
While Not Threadbeenden
Form1.Picture1.ForeColor = QBColor(Int(14 * Rnd))
Ellipse Form1.Picture1.hdc, Rnd * 150, Rnd * 150, Rnd * 150, Rnd * 150
Wend
test_tr = 1
End Function
Private Sub Command1_Click()
hWatchTh = CreateThread(ByVal 0&, 0, AddressOf test_tr, ByVal 0&, _
CREATE_SUSPENDED, WatchThId)
SetThreadPriority hWatchTh, THREAD_PRIORITY_NORMAL
Threadbeenden = False
ResumeThread hWatchTh
End Sub
Private Sub Command2_Click()
Threadbeenden = True
End Sub
Private Sub Command3_Click()
Threadbeenden = True
Unload Me
End
End Sub
Private Sub Command4_Click()
Unload Me
End
End Sub |