InstanceDependencyProperty Class

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Defines a field that is shared by all executing instances of an activity.

Namespace: Microsoft.SpeechServer.Dialog
Assembly: Microsoft.SpeechServer (in microsoft.speechserver.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class InstanceDependencyProperty
[SerializableAttribute] 
public class InstanceDependencyProperty

Remarks

Windows Workflow Foundation restricts any given instance of an activity to running exactly once. To enable control structures, such as while loops or goto branches, in which an activity with a given name (such as myQA1) must execute more than once, a new instance of myQA1 is created by cloning the original instance. The clone exists as long as the original activity is running, after which the clone is destroyed. The cloning is performed by means of serialization; the activity constructor is used only to create the original activity. For this reason, the values on the original instance at the time a clone is created are preserved, but any changes made to the running clone are not propagated back to the original.

For example, suppose a QuestionAnswerActivity is followed by a CodeActivity that examines the QuestionAnswerActivityRecognitionResult value. The running (cloned) QuestionAnswerActivity sets its RecognitionResult while it is running, but then the clone is destroyed when the QuestionAnswerActivity completes execution. By the time the CodeActivity runs, the value of the RecognitionResult available to this activity is that of the original QuestionAnswerActivity, not the updated value made by the clone; that state is lost.

You can eliminate this problem by using an InstanceDependencyProperty to store any values that must be propagated to the original activity. The actual values are then stored with the original copy of the activity, and all the clone (an activity that executes multiple times generates multiple clones) refer to these values to get or set values on the clones. In this way clones become transparent; they all remain synchronized with the original activity, with respect to the member state represented by the InstanceDependencyProperty.

Note

As the best practice, you should always use an InstanceDependencyProperty to store the member state for an activity unless you have a specific reason not to do so. The cloning process can be counterintuitive; by using an InstanceDependencyProperty to store the member state you do not need to be concerned about whether a particular activity is the original or a clone of the original, nor whether a particular property's value differs on an original activity or its clone.

To create an InstanceDependencyProperty, register the property by using the Register method. An InstanceDependencyProperty field is registered in the same way as a DependencyProperty. The following example shows how the IncompleteTimeoutPropertyInstanceDependencyProperty is created and registered.

public readonly static InstanceDependencyProperty IncompletTimeoutProperty = 
  InstanceDependencyProperty.Register("IncompleteTimeout",
                                      typeof(TimeSpan), 
                                      typeof(GetAndConfirmActivity),
                                      Globals.DefaultIncompleteTimeout
                                     );

The preceding definition of IncompleteTimeoutProperty associates this field with the IncompleteTimeout property on GetAndConfirmActivity, specifies the type of the property (System.TimeSpan), and provides a default value for the property (Globals.DefaultIncompleteTimeout).

The following example shows how a property typically retrieves and stores values from its associated InstanceDependencyProperty field. The get and set accessors use GetValue and SetValue, respectively, to retrieve the value from or set the value of the IncompleteTimeoutProperty field.

public TimeSpan IncompleteTimeout
{
  get
  {
    return (TimeSpan)GetValue(IncompleteTimeoutProperty);
  }
  set
  {
    SetValue(IncompleteTimeProperty, value);
  }
}

Inheritance Hierarchy

System.Object
????Microsoft.SpeechServer.Dialog.InstanceDependencyProperty
???????? Microsoft.SpeechServer.Dialog.BindableInstanceDependencyProperty

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

Windows Server 2003

See Also

Reference

InstanceDependencyProperty Members
Microsoft.SpeechServer.Dialog Namespace