Solved

VB6, ActiveX server and threads

Posted on 2000-02-25
8
695 Views
Last Modified: 2008-03-10
Hi

I want to create an ActiveX server using VB6 that keeps some open connections to an Oracle server.

Many clients will create instances of the server on the same machine in the same time.

Each client will try to get an unused connection. If all the connections are used - it will wait. If he gets a connetion - it locks it until he finishes the query.

I need the array of boolean flags(used/not used flag) to be shared for all the instances. Managed to do it by declaring the array in Moudle.

Will each instance use another thread/process (I want the queries be executed in the same time)??

Do I need to use Mutex/Shemaphore/Critical Sections to protect the access to the shared memory?

What's the meaning of the threads number in Project->Options??

Thanks,
Saar Carmi
0
Comment
Question by:saar2
8 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2558088
If you want all apps to access the same flags within the object then you need to set the Instancing property of your object to be be SingleUse or PublicNotCreatable. See the VB Help documentation for the Instancing property for full details.
0
 
LVL 1

Accepted Solution

by:
macu earned 300 total points
ID: 2558386
If you use a single thread (thread pool of 1), all instances will share the same global data, however object method calls will be serialized. If you use a thread pool of > 1 or thread per object, not all objects will shared the same global data (although some may in the thread pool > 1 case.)

Here's another method:

Use a thread pool and set the number of threads to the number of connections you want to allow. Have 'global' data  (in '' because the different threads won't share it) of a single boolean. Have your connection type object set the flag on creation and reset the flag on termination. Before setting the flag however, the object should check if it is already set, if it is it should not allow a connection, but can poll the flag until the object(s) it is sharing the thread with completes (and terminates.) NB, you may want to change where this flag is set/reset in case the clients won't destroy the object when they are finished with a connection. Also, you will have to decide how/whether you want the object to tell the client that a connection is not currently available.

However, doesn't MTS do all this for you? Why not use that instead?
0
 
LVL 4

Author Comment

by:saar2
ID: 2561003
How does the MTS help me?
0
 
LVL 4

Author Comment

by:saar2
ID: 2561584
Adjusted points to 300
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Author Comment

by:saar2
ID: 2561585
I decided that I don't want any client to wait - if there is no available connection I will create another one.

I thought that all the objects share the global memory so I could make a "manager" that controls the number of connection by closing some after not being used for a while.

This cannot be done with thread pool/thread per object ('cause they don't share any memory.

Any other suggestion?

0
 
LVL 1

Expert Comment

by:macu
ID: 2564124
But making use of the fact that instances on different threads do not share global memory is one way of getting around this (as described previously.) NB, the method I described is a bit flawed, you would need to have more than just a boolean globally to allow for queues of objects waiting connections, so that they will gain the connection in the correct order.

However, if you are going to create a new connection for each client, what is the question now?
0
 
LVL 4

Author Comment

by:saar2
ID: 2565899
I have read a book about MTS with VB and it solved all the problems.

Thanks.
0
 

Expert Comment

by:nuwi
ID: 7800715
Could you tell which book was it ?
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

18 Experts available now in Live!

Get 1:1 Help Now