Multithreadeing and activex.exe

Posted on 2001-07-27
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 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???

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


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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:

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Month5 days, 9 hours left to enroll

626 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