[Webinar] Streamline your web hosting managementRegister Today


multithreading with raise event

Posted on 1999-11-11
Medium Priority
Last Modified: 2012-08-13
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!


Question by:bpitzer
  • 2

Accepted Solution

AnswerTheMan earned 800 total points
ID: 2201528
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.


Author Comment

ID: 2202870
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?

Expert Comment

ID: 2204082
<<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...


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question