Property Value Modifications
The VirtualThing class contains several methods that can be called to update the value of a property.
* 
Updating a property value does not send the value to the ThingWorx Platform . To send the value to the platform, you must call the updateSubscribedProperties() method of the VirtualThing class. Publishing properties is done by invoking UpdateSubscribedPropertyValues. Since subscribed properties are per VirtualThing, the publishing of properties is done through a synchronous call to the platform via the C SDK.
The mutex for updateSubscribedProperties is done efficiently. The queue has an efficient mutx. Before invoking the service, the queue is moved to a temporary queue, using a mutex. The temporary queue is then converted to an infotable and published. The use of the temporary queue allows new values to be placed in the permanent properties queue while the blocking service call is invoked.
Methods for Modifying Property Values
The following table lists and briefly describes methods available for the VirtualThing class.
Use
To
setPropertyVTQ(System.String,com.thingworx.types.primitives.structs.VTQ,System.Boolean
Set the value of a property, using a VTQ (value, time, and quality) structure:
name — The name of the property.
value — The VTQ (value, time, and quality) for the property’s value.
forceConnect — Set this value to true to force the value to be sent to the ThingWorx Platform, even if it has not changed. This option is a good option for sending the first value or sending a value immediately after a reconnect.
setPropertyValue(System.String,com.thingworx.types.primitives.IPrimitiveType)
Set the value of a property, using a primitive type:
name — The name of the property.
value — The primitive value.
setProperty(System.String,System.Object)
Set the value of a property, using an object
name — The name of the property.
value — An object representing the value to set. The value is cast to the type of property if possible; otherwise, an exception is thrown.
Platform Subscription to Properties
Before the .NET SDK updates its internally queued property value, the property must first have been subscribed to by the platform. This means that you used ThingWorx Composer to manage bindings. After you click Manage Bindings in the Properties page for a Thing, you can browse for and select the remote properties to 'subscribe to'.
After you start your ConnectedThingClient, a series of bi-directional service calls between the edge and the platform occurs. After perhaps a couple of seconds, the platform invokes the NotifyPropertyUpdate service on the .NET core. The platform sends a list of its subscribed , or "remotely bound", properties with the service, which effectively requests updates to the properties. That list contains the current value for the property on the platform. When the .NET SDK receives this service call, it takes the following actions:
1. Updates its internal list of properties to mark the remotely bound properties as "subscribed". The list is set when the application calls initializeFromAnnotations on the VirtualThing. To check this, call VirtualThing.subscribedProperties.hasSubscription(name).
2. Invokes the following callback of the VirtualThing:
virtual void synchronizeState()
IMPORTANT NOTES
1. Every time the application connects to the platform (either at start or after a disconnected scenario), the platform sends the subscription service call.
2. When the application layer calls setProperty(), the .NET SDK ignores the property update until you have managed the remote bindings so that the property is subscribed to by the platform.
3. The SteamSensorConsole example has code that overrides the synchronizedState() callback. This code does the following:

public override void synchronizeState()
{
// Be sure to call the base class
base.synchronizeState();
// Send the property values to Thingworx when a synchronization is required
base.syncProperties();
}
The example below uses the methods to set new properties and update the values of existing properties.
* 
Be sure to call the updateSubscribedProperties() method on the VirtualThing to send the property values to your ThingWorx Platform. This functionality is also illustrated in the Steam Sensor example.
setPropertyVTQ
VTQ vtq = new VTQ();
vtq.setValue(new NumberPrimitive(123.456));
vtq.setTime(new DateTime());
vtq.setQuality(QualityStatus.GOOD);
base.setPropertyVTQ("MyProperty", vtq);

setPropertyValue
NumberPrimitive value = new NumberPrimitive(123.456);
base.setPropertyValue("MyProperty", value);

setProperty
base.setProperty("MyProperty", 123.456);
Was this helpful?