Share via


Registering for Conversation Events

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 PropertiesChanged 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;
      }
    }
  }
}