Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Multithreadeing and activex.exe

Posted on 2001-07-27
Medium Priority
Last Modified: 2012-08-14
I have an app that needs to update upto 30 clients using tcpip over a slow link. At the moment it does this sequentially..so takes around 30 seconds to do them all. As the protocol is quite slow..ie there is a lot of waiting for anserbacks and stuff...I thought AHHH multithreading! So looking at the VB6 help I found activex.exe files would do the trick and I could set them to one thread per object. I could then generate multiple instances..all in there own thread updating the remote sites...BUT it doesnt work!. When i create an instance of the object and its starts the transaction, my main calling programm stops..until the first object is finished and then creates the next one etc....so im no better off...

Any ideas anyone? Am i doing the wrong thing...can I do multithreading any other way???

Question by:RBETTISON
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

GeoffKell earned 800 total points
ID: 6326202
When you call your ActiveX EXE Set a timer to fire in a short time which then instigates the processing necessary.
The call into the ActiveX EXE is synchronous from the client to which control will not work until it is finished. By using a timer as described will return control immediately then delegate the processing to the ActiveX EXE alone.


Expert Comment

ID: 6326221
Here is some sample code (the class GUICtrl):

Option Explicit

' Define public events
' _____________________|

Public Event SendButtonEventHandler(eventstr As EventStrs)

' Define private events
' _________________________|

Private WithEvents ptmrGUICtrl As Timer

' Define private instances
' _________________________|

Private collEventList As Collection

'> Transfer events form client to server through this public access function
Public Sub SendButtonEvent(eventstr As EventStrs)
' Build up the FIFO event buffer
  collEventList.Add eventstr
End Sub

Private Sub Class_Initialize()
  Set ptmrGUICtrl = iMainForm.tmrGUICtrl
  Set collEventList = New Collection
End Sub

'> Timer function to look for events in the FIFO buffer
'> If there is one -> Raise it
Private Sub ptmrGUICtrl_Timer()
  Dim leventstr As EventStrs
' Check if Something is to do (FIFO buffer is not empty)
  If collEventList.Count <> 0 Then
   ' Get the first ingoing event string from the FIFO Buffer
     Set leventstr = collEventList.Item(1)
     collEventList.Remove 1
   ' Raise the appropriate event
     RaiseEvent SendButtonEventHandler(leventstr)
  End If
End Sub

The class will be embedded in your server class:
Private WithEvents pGUICtrl As GUICtrl

'>  Event handler
'|_________________________________________________________Private Sub pGUICtrl_SendButtonEventHandler(eventstr As EventStrs)
Do related things

This class 'GUICtrl' has a public method 'SendButtonEvent'. This method will be called by
an client. The method add a event to the collection of the class and the class will process the events through the events of the timer control with lays over a form object.

Bye WoK

(This code is from an own Excel Server ...)


Expert Comment

ID: 6326223
Have you tried using a thread pool in your ActiveX dll.

This will give you one thread of execution per object instance. This type of object is a Singleton COM object.

Try it Create an ActiveX exe project with one method.

Increase the thread pool to 100

Create Two projects with timers on each form

In the Timer_Timer event

Create the object
Execute a method (Make sure you can monitor it write to file or something)

You can see that the two will execute at the same time.


What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 10

Expert Comment

ID: 6326263
My famous "Threading without rocket science" example


Expert Comment

ID: 6326395
watching ....
LVL 26

Expert Comment

ID: 6326487
Instead of using thread pool.

Try to set your class instancing to globalsingleuse.

Expert Comment

ID: 6326782
It ss a very bad idea to use globalsigleuse or globalmultiuse with remote component.

Basically  you can?t control your objects.
Sigleuse not a solution because the problem ? com blocking.  
Timer or callback should be used to start multiple concurrent executions.

With sigleuse you got one exe per object so 30 objects ? 30 extra processes on your server.
With multiuse and thread pool > 30 you will get one exe and 3X threads.

Recommended solutions :
1.Raising events but --
Raising events may sometimes does work property with dcom and or mts / com+.

2.Use timer api to create a timer for callback
Example with  event :


timer only :

3. Develop multithread vb client app, it?s difficult but you can do it.

4. Use exesting multithread client such as IIS server.
(create an asp page to run component)


Expert Comment

ID: 6333050
Hang on guys multithreading isnt needed here because of the asynchronous nature of the Winsock control...

It sounds like you just need better management of your socket event code.

Do you want to post what you have to we can better understand the problem? How does it work now?.

is it something like this??

for all clients...

ip = client.IP
loop until connected

winsock1.senddata update

loop until sent


next client

show me what you got!

Expert Comment

ID: 6333168

You seem to be experiencing some difficulty with this site.

Our experts are willing to spend some of their precious time to help you solve your problem. The only thing we're asking in return is some feedback. Did the suggestion help? If it did, grade the question. If it did not, tell the expert so they understand and are able to try again.

Experts-Exchange is not a news group, in which you can post a question, get the answer, and walk away. Or if you get a suggestion that doesn't work, simply ignore it. Instead, the way the site is set up encourages dialogue.

You can read more about how the site works in our member agreement: http://experts-exchange.com/jsp/infoMemberAgreement.jsp

Community Support
LVL 16

Expert Comment

ID: 7707671

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to GeoffKell
Please leave any comments here within the
next seven days.

Expert Comment

ID: 7758302
Finalized as proposed


Community Support Moderator
Experts Exchange

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

730 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