Solved

VB6, ActiveX server and threads

Posted on 2000-02-25
8
699 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 4

Author Comment

by:saar2
ID: 2561584
Adjusted points to 300
0
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

810 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