Global objects using VB, MTS - looking for comments 
Author Message
 Global objects using VB, MTS - looking for comments

I have built a test driver that exhibits some behavior under MTS which I
was hoping someone could fully explain. The basic purpose of the test
driver is to test the behavior of a VB singleton (a class whose
instances access global variables in a BAS module) under MTS; will it
share data across clients, etc.

My understanding from reading documentation describing MTS's single
threaded apartment model was that different clients would not share
data, since each client would access its instances of the singleton from
a different thread which would get its own copy of the global data in
thread local storage. However, the behavior I am seeing is that all
clients do in fact share the global state as long as the DLL under MTS
stays in memory (I have changed the MTS package properties to remain in
memory even when idle). For a more complete description of my test
case, see below..

My questions are, why does my test exhibit this behavior? Is this
behavior reliable? Why NOT use this approach? (Since it appears to be
frowned upon in all documentation I've read).

Test case:
1. Class1 has a single member variable - a long counter. It has a get
property which increments and returns the counter.

2. A BAS module contains a global instance of Class1, Newed when it is
first accessed.

3. Class2 has a Class1 instance as a member, which is set to reference
the global instance upon initialization. Class2 has a single method
which returns the Class1 counter property.

4. All of the above are contained in a single DLL which run under MTS
and don't support transactions.

5. On the client, a form has a button which when pressed New's a Class2
instance, runs the method to return and display the counter and sets the
Class2 to Nothing.

6. On any client machine and in every running copy of the client, the
counter return shows that they are all accessing the same global
counter.

thanks,
phil usatine



Tue, 29 Jan 2002 03:00:00 GMT  
 Global objects using VB, MTS - looking for comments
What you are seeing is exactly how MTS treats instances of objects with the
default instancing propert of MultiUse. Using global variables within
components is a no-no when porting them to MTS. Use the Shared Property
Manager instead.

To change the behaviour you are describing, change the instancing property
to SingleUse. This cause each instance to serve a single client only and the
global variables will not be 'shared'.

--
Mark Freeman
MCSE, MCT, MCP-VB6, A+



Quote:
> I have built a test driver that exhibits some behavior under MTS which I
> was hoping someone could fully explain. The basic purpose of the test
> driver is to test the behavior of a VB singleton (a class whose
> instances access global variables in a BAS module) under MTS; will it
> share data across clients, etc.

> My understanding from reading documentation describing MTS's single
> threaded apartment model was that different clients would not share
> data, since each client would access its instances of the singleton from
> a different thread which would get its own copy of the global data in
> thread local storage. However, the behavior I am seeing is that all
> clients do in fact share the global state as long as the DLL under MTS
> stays in memory (I have changed the MTS package properties to remain in
> memory even when idle). For a more complete description of my test
> case, see below..

> My questions are, why does my test exhibit this behavior? Is this
> behavior reliable? Why NOT use this approach? (Since it appears to be
> frowned upon in all documentation I've read).

> Test case:
> 1. Class1 has a single member variable - a long counter. It has a get
> property which increments and returns the counter.

> 2. A BAS module contains a global instance of Class1, Newed when it is
> first accessed.

> 3. Class2 has a Class1 instance as a member, which is set to reference
> the global instance upon initialization. Class2 has a single method
> which returns the Class1 counter property.

> 4. All of the above are contained in a single DLL which run under MTS
> and don't support transactions.

> 5. On the client, a form has a button which when pressed New's a Class2
> instance, runs the method to return and display the counter and sets the
> Class2 to Nothing.

> 6. On any client machine and in every running copy of the client, the
> counter return shows that they are all accessing the same global
> counter.

> thanks,
> phil usatine



Tue, 29 Jan 2002 03:00:00 GMT  
 Global objects using VB, MTS - looking for comments

Quote:

> What you are seeing is exactly how MTS treats instances of objects with the
> default instancing propert of MultiUse. Using global variables within
> components is a no-no when porting them to MTS. Use the Shared Property
> Manager instead.

Why is the use of global variabled a no-no?

thanks,
phil usatine



Tue, 29 Jan 2002 03:00:00 GMT  
 Global objects using VB, MTS - looking for comments
Because the MS documentation and MOC courseware says so. Microsoft wrote
MTS, so I follow their recommendations (most of the time).

Mark Freeman
MCSE, MCT, MCP-VB6, A+


Quote:

> > What you are seeing is exactly how MTS treats instances of objects with
the
> > default instancing propert of MultiUse. Using global variables within
> > components is a no-no when porting them to MTS. Use the Shared Property
> > Manager instead.

> Why is the use of global variabled a no-no?

> thanks,
> phil usatine



Tue, 29 Jan 2002 03:00:00 GMT  
 Global objects using VB, MTS - looking for comments
I don't have all of the letters after my name like our friend Mark, but I
can give you a real answer.

Global STATIC values are fine.  The concern with global variables is that
with MTS, objects are reused.  Therefore, you can't be assured of what the
value of these globals are when MTS passes you an instance.  The last user
of the object could have set them to anything before you got it.  You can't
count on reinitializing the globals in your object's constructor either
because MTS will create the object once, the reuse it several times before
destruction firing the constructor only once despite using the object
several times/


Quote:

>> What you are seeing is exactly how MTS treats instances of objects with
the
>> default instancing propert of MultiUse. Using global variables within
>> components is a no-no when porting them to MTS. Use the Shared Property
>> Manager instead.

>Why is the use of global variabled a no-no?

>thanks,
>phil usatine



Sun, 03 Feb 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Global MTS Object

2. Looking for MTS SDK and MTS Spy

3. MTS and Non MTS objects from same code

4. Global Variables / Global Objects

5. error when using MTS object in a vbscript

6. Comments on my MTS componant

7. Using GlobalMultiUse DLL from MTS COM object

8. ADO, Oracle, MTS, using command object to open Recordset

9. Comments on my MTS componant

10. Error 429: ActiveX can't create object, using MTS

11. Using Global objects

12. Using Global Objects

 

 
Powered by phpBB® Forum Software