Code Listing: Handling Platform Events in C#

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.

The following C# code example shows how to handle events raised by an instance of the IUccPlatform interface. When the OnShutdown event is received, the registered _IUccPlatformEvents events are unadvised. This process helps to prevent the application from leaking memory due to the unadvised events.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.UccApi;

namespace UccApiComponents
{
    public partial class UccApiPlatform :  _IUccPlatformEvents
    {
        /// <summary>
        /// Handling _IUccPlatformEvents.OnIpAddrChanged event
        /// </summary>
        public event EventHandler<IpAddrChangedEventArgs> OnIpAddrChanged;

        /// <summary>
        /// Handling _IUccPlatformEvents.OnShutdown event
        /// </summary>
        public event EventHandler<ShutdownEventArgs> OnShutdown;

        #region UccPlatform-related events:

        void _IUccPlatformEvents.OnIpAddrChange(
                    UccPlatform eventSource,
                    object eventData)
        {
            if (OnIpAddrChanged != null)
                RaiseEvent(OnIpAddrChanged, new IpAddrChangedEventArgs(eventSource, eventData));
        }

        void _IUccPlatformEvents.OnShutdown(
                    UccPlatform eventSource,
                    IUccOperationProgressEvent eventData)
        {
            if (this.isShutdown == false)
                this.UnadviseForEvents<_IUccPlatformEvents>(eventSource, this);
            isShutdown = true;
            
            // Bubble up the event to the caller.
            if (OnShutdown != null)
                RaiseEvent(OnShutdown, new ShutdownEventArgs(eventSource, eventData));
        }

        #endregion UccPlatform-related events:
    }
}

See Also

Concepts

Code Listing: Programming Platform Object in C#