Multithreadeing and activex.exe

I have an app that needs to update upto 30 clients using tcpip over a slow link. At the moment it does this takes around 30 seconds to do them all. As the protocol is quite 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 im no better off...

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

Who is Participating?
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.

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 ...)

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.


Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

My famous "Threading without rocket science" example

watching ....
Instead of using thread pool.

Try to set your class instancing to globalsingleuse.
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)

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!

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:

Community Support

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.
Finalized as proposed


Community Support Moderator
Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.