Using Shared Property Manager

What is Shared Property Manager?

We know that most of the times MTS objects are stateless. But sometimes it becomes necessary to persist properties or state of the object. MTS provides this functionality via Shared Property Manager.

There are three objects which we need to deal with :

  • SharedPropertyManager
  • SharedPropertyGroup
  • SharedProperty

SharedPropertyManager is at top level in the hierarchy. It allows a property to be shared across multiple clients.

SharedPropertyGroup represents a logical grouping of properties and is next in the hierarchy.

SharedProperty represents actual property of an object.

How to code for shared properties?

First you need to set reference to Shared Property Manager Type Library.

Consider following code :

Dim propmanager As MTxSpm.SharedPropertyGroupManager
Dim propgrp As MTxSpm.SharedPropertyGroup
Dim prop As MTxSpm.SharedProperty
Dim flag As Boolean
Dim myvar as String

Set propmanager = New MTxSpm.SharedPropertyGroupManager
Set propgrp = propmanager.CreatePropertyGroup("mygrp", LockSetGet, Process, flag)
Set prop = propgrp.CreateProperty("myprop", flag)
If flag = False Then
    prop.Value = "myvalue"
End If

You need to add this code in the method in which you want to set or get the property value. Note that the property is always created even though it already exists. The boolean value(flag) tells you weather the property already exists or not.

The LockSetGet places lock on the property while setting or retrieving the value. Other possible value is LockMethod which locks all the properties until the current method finishes.

The Process indicates that the property will be destroyed when the package is shut down. Other possible value is Standard in which case the property is destroyed when all the client references are released.

Bipin Joshi is an independent software consultant and trainer by profession specializing in Microsoft web development technologies. Having embraced the Yoga way of life he is also a yoga mentor, meditation teacher, and spiritual guide to his students. He is a prolific author and writes regularly about software development and yoga on his websites. He is programming, meditating, writing, and teaching for over 27 years. To know more about his private online courses on ASP.NET and meditation go here and here.

Posted On : 18 December 2000

Tags : Components Windows