Click to See Complete Forum and Search --> : Are "Threads" impossible in VB?


S.L.Swamy
October 3rd, 2001, 07:06 AM
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

Cimperiali
October 3rd, 2001, 09:10 AM
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

Cakkie
October 3rd, 2001, 10:07 AM
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
slisse@planetinternet.be

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

scriptslave
January 11th, 2002, 10:48 AM
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.

Iouri
January 11th, 2002, 11:08 AM
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
iouri@hotsheet.com

softweng
January 11th, 2002, 12:29 PM
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

terryl
January 31st, 2002, 04:08 PM
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.