CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2000
    Location
    India
    Posts
    25

    Are "Threads" impossible in VB?

    I want to create a thread in VB. When i tried doing it, i couldn't do it successfully, infact the program crashes. Are there any issues like,threads are impossible in VB?

    A sample code can of great help.

    Regards,
    swamy dada


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Are "Threads" impossible in VB?

    Francesco Balena (check internet for: vb2themax) told about this in his book. I have not studied the lesson well, so I am not really sure, but he spoked about building two activex.exe (server and client, both activex.exe). Maybe checking his web page...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Are "Threads" impossible in VB - Addition to Cimperiali?

    Let us just say that threads aren't possible on a stable way in VB. I have seen many projects, using a bunch of API calls. All those projects were unstable, and crashed constantly.

    What Cimperiali mentioned, activex exe's. This is probably the most stable way to do "multithreading" in VB. The plan is simple, a VB program only has 1 thread, but since an Activex exe is a seperate program, it has a seperate process id and a seperate thread. The trick is to use a timer in the Activex exe. The timer will do the actual processing, and is only used to return control to the calling program. If we didn't use a timer, the calling program would wait until the activex exe finished processing.
    an example

    ' ***********
    ' ActiveX exe
    ' ***********

    private Sub Timer1_Timer()

    ' Do some processing here
    Timer1.Enabled = false
    MsgBox "This is the ActiveX Exe speaking"

    End Sub

    public Sub StartProcessing()

    Timer1.Interval = 1
    Timer1.Enabled = true

    End Sub

    ' **********
    ' VB Program
    ' **********
    private Sub Command1_Click()

    ' MyActiveXProject.MyActiveXExe is the program from above
    Dim myAExe as new MyActiveXProject.MyActiveXExe

    myAExe.StartProcessing
    Msgbox "This is the VB Program speaking"

    End Sub



    When you run the code, you should see two messageboxes, where normall, you can only see one

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    May 2001
    Posts
    17

    Re: Are "Threads" impossible in VB - simult. processing

    What if we didn't want any control over the thread, we just wanted simultaneous execution? I need to simply create an object that can do it's own thing and call one of my methods when something happens (i need to let about 20 objects do stuff simultaneously), I don't care about stopping, sleeping, etc the thread.


  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Are "Threads" impossible in VB - simult. processing

    You can include DoEvents into each app to let others to work and then Send messages from one app to another using SendMessage API. Because handles of the app windows will be different every time, all your app you have to starrt with determining of the window of the current app and then kepp them somewhere accessible by each app (ini file for example)

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  6. #6
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: Are "Threads" impossible in VB?

    You can multithread easily if you are willing to use VB.NET
    It is part of Visual Studio 7.0 (.NET). I have developed a few
    apps using multithreading with VB.NET and it seems to work great.
    Just something to look at. The Release version of VS 7.0 is supposed to be next month.

    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

  7. #7
    Join Date
    Apr 2001
    Location
    P.J., Malaysia
    Posts
    9

    Re: Are "Threads" impossible in VB - simult. processing

    did u try to contruct a dummy Timer class that does not have any form or control, which only provide the events of OnTimer? it work, becouse i'm doing it this way.


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

Featured