multithreading with raise event

I have checked out the "Coffe Monitor" example in the online books for VB.
I need to do something similar where I:

- create a standard EXE
- have it call an activex EXE that is configured for a new thread for each instance
(I have to be able to create a dynamic number of these, not sure how many I need to create until runtime)

- utilize callbacks to standard EXE which pass parameters indicating status, etc when
it completed

The coffeemonitor example is a little more complex than I need, and kinda hard to follow for me.
I just could use a real simple example that does this.
I want every component in each thread to use the same callback procedure on the standard exe.

Any help or sample you could send me would be appreciated!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

here is a simple example to create ActiveX EXE  along with the client using it :

start an ActiveX EXE project.
project->properties->projectName - set to "ModalTest"
project->properties->startup object=none
move to COmponent TAB and check the 'ActiveX Component' radio button.

in Class 1, add the folwing code :
Option Explicit
Private WithEvents frmOne As Form1
Public Event T20()
Public Sub start()
End Sub

Private Sub Class_Initialize()
    Set frmOne = New Form1
    Unload Form1
    Set Form1 = Nothing
End Sub

Private Sub Class_Terminate()
   Unload frmOne
    Set frmOne = Nothing
End Sub

Private Sub frmOne_twenty()
    RaiseEvent T20
End Sub
add Form1 to the project.
set it caption to "ActiveX EXE form"
add a label and a Timer control to the form.
add the folwing code to Form1 :
Option Explicit
Private C As Long
Public Event twenty()
Private Sub Form_Load()
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Label1 = C
    C = C + 1
    If C = 20 Then RaiseEvent twenty
End Sub

save the project in a new folder, then File->make EXE into that folder.
close the project.

now, start a new STANDARD EXE project (the client).
in project->References, click 'BROWSE'.
change the combobox to display EXE files, then browse for ModalTest.exe (the ActiveX EXE you've created).
click open, then OK.

now, place a Command Button on Form1 and add the folwing code to Form1 :
Option Explicit
Private WithEvents A As ModalTest.Class1

Private Sub A_T20()
End Sub

Private Sub Command1_Click()
    Command1.Enabled = False
    Set A = New ModalTest.Class1
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set A = Nothing
End Sub
then, add another form (Form2).
run the project. click the button.
the ActiveX EXE form popup, and start a 20 count. at 20, the ActiveX EXE raises an event to the client which as a response - shows another form.

hope that will give you some STARTING point.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bpitzerAuthor Commented:
What if you wanted to spawn off several of modaltest.class1's all at the same time?

It appears it doesn't work properly, that only the last one submitted returns?

(verified by passing parameter with event callback to tell which one fired it)

Any clue?
<<What if you wanted to spawn off several of modaltest.class1's all at the same time?
it was just an *EXAMPLE* of how to make it. this onw generated only ONE instance of the object, but you can instanciate as many objects as your PC can stand :

Private WithEvents A As ModalTest.Class1

Private WithEvents B As ModalTest.Class1

Private WithEvents C As ModalTest.Class1

and later :
Set A = New ModalTest.Class1
Set B= New ModalTest.Class1
Set C= New ModalTest.Class1

now, in the ActiceX EXE project->properties, you can define that each object created will run in a SEPERATE THREAD.

you can do many things. you can add objects created to a collection..etc..

now, in this particular example - since the object event cause the client to show form2 - the form2 will be displayed only once, but you can add more functionnallity... that's just an example for you to START somewhere...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.