Re: Creating Thread under VB




"akuma" <akuma@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C8D0F5A7-DF3D-48EE-A85B-DB02FC708DB8@xxxxxxxxxxxxxxxx
>I have problems of creating thread under VB. VB crush when the CreateThread
> fucntion called. After correct the wrong declaration copied from the API
> viewer from:
> Private Declare Function CreateThread Lib "kernel32" (lpThreadAttributes
> As
> Any, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As
> Any,
> ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
> to:
> Private Declare Function CreateThread Lib "kernel32" (lpThreadAttributes
> As
> Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter
> As
> Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
>
> A thread was created under IDE. However, the CreateThread function can't
> run
> more than once and it is ignored inside the For loop. Sometimes, the
> thread
> was created once and sometimes it crush under IDE. After compile the code
> to
> the EXE file it crushes all the time.
>


VB6 is not thread-safe. Creating threads as you're doing is going to be
unpredictable at best. This is documented in the KB:

PRB: Access Violation in VB Run-Time Using AddressOf
http://support.microsoft.com/default.aspx?scid=kb;en-us;198607


--
Mike
Microsoft MVP Visual Basic


.



Relevant Pages

  • Creating Thread under VB
    ... VB crush when the CreateThread ... Private Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As ...
    (microsoft.public.vb.winapi)
  • Re: Creating Thread under VB
    ... Hence CreateThread ... VB6 is thread-safe in the STA object model. ... > Private Declare Function CreateThread Lib "kernel32" (lpThreadAttributes ...
    (microsoft.public.vb.winapi)