Instructor-led online courses in ASP.NET Core, ASP.NET MVC, and ASP.NET Design Patterns. Read more...
Instructor-led online courses in ASP.NET Core, ASP.NET MVC, and ASP.NET Design Patterns. Conducted by Bipin Joshi on weekends. More details are available here.

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 a software consultant, trainer, author and spiritual yoga mentor having 23+ years of experience in software development. He teaches online training courses in ASP.NET Core, Angular, and Design Patterns to individuals and small groups. 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 Ajapa Yoga to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 18 December 2000

Tags : Components Windows

Subscribe to our newsletter

Get monthly email updates about new articles, tutorials, code samples, and how-tos getting added to our knowledge base.