Solved

Threading issue with VB6

Posted on 2004-08-21
12
231 Views
Last Modified: 2013-11-13
Hi,
   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

Regards
Thanks in advance
Noby E A
0
Comment
Question by:xlteknologies
  • 2
  • 2
  • 2
  • +2
12 Comments
 

Expert Comment

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

bye.
0
 

Expert Comment

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

Author Comment

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

Bye

0
 
LVL 5

Expert Comment

by:vadivhere
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 :)

Cheers!!!!
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:xlteknologies
ID: 11858319
Hi,
   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 !!
0
 
LVL 3

Accepted Solution

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

Regaurds,
Dave
0
 
LVL 3

Expert Comment

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

Regaurds,
Dave
0
 
LVL 3

Assisted Solution

by:Julian_C
Julian_C earned 87 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?

Cheers
Julian
0
 
LVL 3

Expert Comment

by:Julian_C
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?

Cheers
Julian
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

746 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