VB Multithreading
-
Hello, I am trying to run a multithread sort of application. But the compiled code is giving problems. In gives memory access violation. Pl. help. In .frm file--> Option Explicit Const CTF_COINIT = &H8 Const CTF_INSIST = &H1 Const CTF_PROCESS_REF = &H4 Const CTF_THREAD_REF = &H2 Private Declare Function SHCreateThread Lib "shlwapi.dll" (ByVal pfnThreadProc As Long, pData As Any, ByVal dwFlags As Long, ByVal pfnCallback As Long) As Long Private Sub Command1_Click() Dim i As Long SHCreateThread AddressOf NewThread, ByVal 0&, CTF_INSIST, ByVal 0& ' SHCreateThread AddressOf NewThread1, ByVal 0&, CTF_INSIST, ByVal 0& ' For i = 1 To 10000 ' Me.Caption = i ' Next End Sub in .bas file--> Option Explicit Sub NewThread() MsgBox "Messagebox, called from thread!" End Sub 'Sub NewThread1() ' MsgBox "Messagebox, called from thread ONE!" 'End Sub Regards, ~A.
-
Hello, I am trying to run a multithread sort of application. But the compiled code is giving problems. In gives memory access violation. Pl. help. In .frm file--> Option Explicit Const CTF_COINIT = &H8 Const CTF_INSIST = &H1 Const CTF_PROCESS_REF = &H4 Const CTF_THREAD_REF = &H2 Private Declare Function SHCreateThread Lib "shlwapi.dll" (ByVal pfnThreadProc As Long, pData As Any, ByVal dwFlags As Long, ByVal pfnCallback As Long) As Long Private Sub Command1_Click() Dim i As Long SHCreateThread AddressOf NewThread, ByVal 0&, CTF_INSIST, ByVal 0& ' SHCreateThread AddressOf NewThread1, ByVal 0&, CTF_INSIST, ByVal 0& ' For i = 1 To 10000 ' Me.Caption = i ' Next End Sub in .bas file--> Option Explicit Sub NewThread() MsgBox "Messagebox, called from thread!" End Sub 'Sub NewThread1() ' MsgBox "Messagebox, called from thread ONE!" 'End Sub Regards, ~A.
Your code has so many problems I can't even begin to list them. Go here: www.powervb.com and buy the book. That's the only correct way to do threads in VB, period. Anything else is a hack, even if it seems to kinda work. ___________ Klaus [www.vbbox.com]