Results 1 to 6 of 6

Thread: How to use CreateThread in VB6.0,win2000

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    1

    How to use CreateThread in VB6.0,win2000

    can anybody give me an example which uses CreateThread to make a MultiThread VB Project?Thank you very much.

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    As far as I know, there is no way of using CreateThread relyable with VB6. VB6 creates single threaded apartment applications, which can not create extra threads without problems.

  3. #3
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    VB Code:
    1. 'Using the CreateThread function in Visual Basic
    2. 'is very risky! VB5 is 'kinda' stable, but VB6
    3. 'applications will probably crash when you
    4. 'use the CreateThread function.
    5.  
    6. 'In a form
    7. 'Add a command button to the form
    8. Private Sub Command1_Click()
    9.     'KPD-Team 1999
    10.     'URL: [url]http://www.allapi.net/[/url]
    11.     'E-Mail: [email][email protected][/email]
    12.     'After you click this button, try to move the window
    13.     'You will see that the AsyncThread-function was executed asynchronously
    14.     hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
    15.     CloseHandle hThread
    16. End Sub
    17. Private Sub Form_Unload(Cancel As Integer)
    18.     'If the thread is still running, close it
    19.     If hThread <> 0 Then TerminateThread hThread, 0
    20. End Sub
    21. 'In a module
    22. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    23. 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
    24. Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
    25. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    26. Public hThread As Long, hThreadID As Long
    27. Public Sub AsyncThread()
    28.     'Let this thread sleep for 10 seconds
    29.     Sleep 10000
    30.     hThread = 0
    31. End Sub
    Please rate my post.

  4. #4
    New Member
    Join Date
    May 2003
    Location
    New York
    Posts
    10

    Smile Safe VB6 Multithreading

    The CreateThread API call is very dangerous. Many programmer's are misguided about multithreading VB6 applications. Their left to believe that calling the CreateThread API call is all that’s needed to create multithreaded VB6 apps. Ultimately its NEVER reliable because its missing the underlying foundation needed to safely implement multithreading in VB6.

    COM objects live in Apartments, to implement multithreading safely you must create a new STA apartment for each new thread you create. You must also create a Message pump for that Apartment so objects can properly communicate and marshal calls. These are only the basics, but its the ONLY safe way to truly implement multithreading in VB6.

    My company HalfTime Technologies, Inc. publishes a product called Thread Factory that is specifically designed to safely implement VB6 multithreading. Its completely COM compliant and safe. I invite you to download the evaluation version from our site and see for yourself. The software includes comprehensive HTML help file, tutorials and examples.

    http://www.halfx.com.

    Thread Factory empowers VB6 programmers to easily create robust multithreaded apps, components and OCX controls. Many Wall street investment banks and universities have licensed our products. Just last week the Astrophysics dept at John Hopkins University licensed our product.

    FYI, The download also includes StopWatchPro - a multithreaded stop watch OCX control thats accurate to 1 millisecond.

    Thanks,
    Michael Miller

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Way to dig up a post to peddle your own software! Maybe you and that Katan guy can get together.
    Please rate my post.

  6. #6
    New Member
    Join Date
    May 2003
    Location
    New York
    Posts
    10

    I try to be objective and helpfull

    Unfortunately I rely mainly on consulting for income. But the Job Market here in NY is terrible so I'm leveraging my software skills through products I created instead. I created some pretty cool stuff IMHO, so hopefully something good will come from it.

    I have a wife, 3 kids and a telescope to support.

    Love to talk, but I must peddle some more

    Best of Luck to You !
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width