Solved

Multithreadeing and activex.exe

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


0
Comment
Question by:RBETTISON
12 Comments
 
LVL 5

Accepted Solution

by:
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.

Regards
GK
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
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 ...)



0
 
LVL 4

Expert Comment

by:VincentLawlor
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.

Vin.


0
 
LVL 10

Expert Comment

by:caraf_g
ID: 6326262
0
 
LVL 10

Expert Comment

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

:)
0
 
LVL 4

Expert Comment

by:amit_panjwani
ID: 6326395
watching ....
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 6326487
Instead of using thread pool.

Try to set your class instancing to globalsingleuse.
0
 
LVL 5

Expert Comment

by:rkot2000
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 :

http://support.microsoft.com/support/kb/articles/Q176/9/51.ASP?LN=EN-US&SD=gn&FR=0&qry=callback&rnk=12&src=DHCS_MSPSS_gn_SRCH&SPR=VBB

timer only :
http://support.microsoft.com/support/kb/articles/Q180/7/36.ASP?LN=EN-US&SD=gn&FR=0&qry=callback&rnk=14&src=DHCS_MSPSS_gn_SRCH&SPR=VBB

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)

0
 
LVL 1

Expert Comment

by:LuckyPhill
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
winsock1.connect
do
 doevents
loop until connected

winsock1.senddata update

do
 doevents
loop until sent

winsock1.close

next client

show me what you got!
0
 
LVL 3

Expert Comment

by:modder
ID: 6333168
RBETTISON,

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

modder
Community Support
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7707671
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

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

Expert Comment

by:modulo
ID: 7758302
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now