[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Threading issue with VB6

Posted on 2004-08-21
Medium Priority
Last Modified: 2013-11-13
   I am developing a winsock server using VB 6. I have created My winsock OCX using api programming in VB 6. Now that I have the OCX, I tried to load an array of my ocx in a vb exe project ( My Server Application , Chat server ).

For each connection, I would load one of my control using the index property of the ocx control.

I am using      load srv(1)   ' to load controls
and                unload srv(1) ' to unload controls

The problem is that all the controls I load, work on the same thread as the parent application.

I need all my controls ( the whole array ) to share a thread pool. How can I do it.

I though of Activex EXE. So the problem is that I am not able to load an array of activex exe dlls in my exe project and use different events associated with the control. As My parent application needs to know certain issues like activity status, connected number , disconnected number, i need to use events. We are able to set the index property of a normal ocx in our project and load an array of that control, So then why cant we load an activex exe dll array.

Can some one please suggest me a solution for my problem

Thanks in advance
Noby E A
Question by:xlteknologies
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
  • 2
  • 2
  • 2
  • +2

Expert Comment

ID: 11858041
I develope something just the way you wanted, i did it by creating a form with a winsock object,  and in the program i create a dinamyc array of this form.

Every time a connection was accepted i check for closed connections (a public property of the form) or create a new one to be waiting for the next connection.

Each instanced form will work alone in a new thread...

Thats the way i solve the problem...

I Hope it could be useful for you


Expert Comment

ID: 11858047
By the way, you can create ActiveX objects with visual components you just have to look how to do it

Author Comment

ID: 11858187
Your suggestion is very much valid. But loading so many forms, is it okay.

For eg, if the server should give approximately 5000 connections, 5000 forms will be loaded. I am not sure whether this will create any issue. Are you sure this will work.

Another issue I faced is, even if we keep the form property as invisible and load the form in a different thread, it displays. Then I inserted the code in the form load to make it invisible. still it flickers on the screen. can this be solved.



Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Expert Comment

ID: 11858313
In the ocx program, you have to instantiate the ocxs like what we do with forms like this,

Dim a as new frmInstant

So, when ever the ocx is instantiated in your vb proj like ocxcontrol.load(1), then it will call new instance not the existing one.

Sorry, am running out of time so i cant breif the answer more. But, ask me if you are not able to understand the thing what iam speaking.

If you got some hint thru my answer, let me to bag the points :)


Author Comment

ID: 11858319
   I did not really understand what you explained. if I am correct, in the initialise part of the user control on the OCX, we have to write some code to open the usercontrol in a new thread.

I would be very gratefull if you can provide me some light into this matter, on how to do it.

Bye !!

Accepted Solution

Stimphy earned 352 total points
ID: 11860638
Create an ActiveX EXE project for all your sockets.  This runs outside of the application thread.


Expert Comment

ID: 11863110
OK... to clarify alittle bit,
   You may not need an array of classes or winsocks available to your application, after all, your only interested in getting data that is sent to the hosting application right?

So in the activeX EXE, you could do something like this..
'Add a form and put your sockets on it, with your code
'Add this code to your public class and intergrade it into the form code.
'Build It

'This event will be used to tell you that some data has arrived from this socket.
'Your application receives the calling socket, so if a response is needed, you can do it.
Public Event DataArrival(tempSocket As Winsock, Data As String)

'Maybe you want to block certin host connections... Do it with this.
Public Event ConnectionRequest(RemoteHost As String)
Public BlockConnection as boolean

Friend Sub DataEvent(tempSocket As Winsock, Data As String)
    RaiseEvent DataArrival(tempSocket, Data)
End Function

Friend Sub ConnectionEvent(RemoteHost As String) as boolean
    BlockConnection=False  'Available for the hosting appliction
    RaiseEvent ConnectionRequest(RemoteHost)
    ConnectionEvent = BlockConnection
End Function

Obviously there is more work to do, but this should get you on the right track.


Assisted Solution

Julian_C earned 348 total points
ID: 11879400
If you just need to slip the current thread and call methods on another then there are countless examples using a call to the WIn32 timer API, passing the addressof the method you wish to call. In this way the method is called when the timer fires in a new thread that the timer creates. You just set the timer to fire almost instantly and there is no discernable performance hit. If this is the direction you want to go then let me know and I'll dig out some examples. The concept sounds easy enough and I've used it myself to great effect but it is very hard to debug etc as the multithreading is not understood natively. I always debug single threaded once I've proved that the multihtreading works and just turn on the multithreading in the compiled version.

Do you need an example or is this way off the mark?


Expert Comment

ID: 12070175
Personally, I think that the answers were on the wrong lines up to Stimpy's comment. I added mine as a sort of lateral jump into multithreading in VB6. Other comments really used multithreading by using different processes for each thread. My solution provides multithreads in the same process space. It isn't offically supported but it works and came in very handy for me in the bad old days before .net :-) Anyway, I think the points should be split down the middle. OK?


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Starting up a Project
Suggested Courses

649 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