Registering for Conversation Events

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.

Conversations expose several events that can be useful to an application, and may represent a good handle for the application developer to invoke business logic, or adjust a user interface. For example, the StateChanged event is raised when the state of the conversation changes, and the PropertiesChanged event is raised when a property of the conversation such as Subject or Id changes.

The following code demonstrates registering for the StateChanged event and the implementation of a simple handler for this event.

conversation.PropertiesChanged += Conversation_PropertiesChanged;

private void Conversation_PropertiesChanged(object sender, PropertiesChangedEventArgs<ConversationProperties> e)
{
  if (e.ChangedPropertyNames != null)
  {
    //Update the property from property changed event
    foreach (string propertyName in e.ChangedPropertyNames)
    {
      switch (propertyName)
      {
        case ConversationProperties.ConversationIdPropertyName: 
          Console.WriteLine("Conversation id changed to {0}", e.Properties.Id);
          break;
        case ConversationProperties.ConversationPriorityPropertyName: 
          Console.WriteLine("Conversation priority changed to {0}", e.Properties.Priority);
          break;
        case ConversationProperties.ConversationSubjectPropertyName:
          Console.WriteLine("Conversation subject changed to {0}", e.Properties.Subject);
          break;
        case ConversationProperties.ConversationActiveMediaTypesPropertyName:
          Console.WriteLine("Conversation active media types property name changed to");
          foreach (string activeMedia in e.Properties.ActiveMediaTypes)
          {
            Console.WriteLine(activeMedia);
          }
          break;
        default:
          //Should not reach here
          Debug.Assert(false, "property name not expected");
          break;
      }
    }
  }
}