December 2017 : Online courses in ASP.NET MVC and Angular 4. Conducted by Bipin Joshi. Read more...
Registration for December 2017 batches of ASP.NET MVC / Core and Angular 4 online courses have already started. Conducted by Bipin Joshi. Book your seat today ! Click here for more details.

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"
else
   myval=prop.value
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 a software consultant, an author and a yoga mentor having 22+ years of experience in software development. He also conducts online courses in ASP.NET MVC / Core and Design Patterns. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Meditation and Mindfulness to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 18 December 2000


Tags : Components Windows