Conversation.BeginTerminate Method (AsyncCallback, Object)

Begins an asynchronous operation to terminate the conversation.

Namespace:  Microsoft.Rtc.Collaboration
Assembly:  Microsoft.Rtc.Collaboration (in Microsoft.Rtc.Collaboration.dll)

Syntax

'Declaration
Public Function BeginTerminate ( _
    userCallback As AsyncCallback, _
    state As Object _
) As IAsyncResult
'Usage
Dim instance As Conversation
Dim userCallback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginTerminate(userCallback, _
    state)
public IAsyncResult BeginTerminate(
    AsyncCallback userCallback,
    Object state
)

Parameters

  • userCallback
    Type: System.AsyncCallback
    The method to be called when the asynchronous operation is completed.
  • state
    Type: System.Object
    A user-provided object that distinguishes this particular asynchronous operation from other asynchronous operations.

Return Value

Type: System.IAsyncResult
An IAsyncResult that references the asynchronous operation.

Remarks

Terminates the conversation by first terminating all the calls, the conference session and conference invitations associated with this conversation.

Examples

The following example shows how to terminate a conversation. Every conversation needs to be terminated to ensure that no memory leaks are introduced. This is true even if the conversation had no calls or conferences active.

C# Resuming previous conversation

 
ConversationSettings settings = new ConversationSettings();
settings.Subject = _previousSubject;
settings.Id = _previousConversationId;
settings.Priority = ConversationPriority.Normal;

_conversation1 = new Conversation(_endpoint1, settings);
            #endregion SpecifyConversationSettings

            #region CreateIMCall
_imCall1 = new InstantMessagingCall(_conversation1);

_conversation1.BeginTerminate(
    this.ConversationTerminated,
    _conversation1 /*state*/);
                #endregion TerminateConversation

                TestUtilities.Helper.AssertEvent(shutdownCompleted, "IM Call 2 did not shut down.");
                _imCall2 = null;

                if (_conversation2 != null)
                {
                    _conversation2.BeginTerminate(
                        this.ConversationTerminated,
                        _conversation2 /*state*/);
                }
            }

            if (_endpoint1 != null)
            {
                _endpoint1.BeginTerminate(
                    result =>
                    {
                        _endpoint1.EndTerminate(result);
                        shutdownCompleted.Set();
                    },
                    null);

                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Endpoint 1 shutdown did not complete.");
                _endpoint1 = null;
            }

            if (_endpoint2 != null)
            {
                _endpoint2.BeginTerminate(
                    result =>
                    {
                        _endpoint2.EndTerminate(result);
                        shutdownCompleted.Set();
                    },
                    null);

                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Endpoint 2 shutdown did not complete.");
                _endpoint2 = null;
            }

            if (_platform1 != null)
            {
                _platform1.BeginShutdown(
                    result =>
                    {
                        _platform1.EndShutdown(result);
                        shutdownCompleted.Set();
                    },
                        null);
                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Platform 1 shutdown did not complete.");
                _platform1 = null;
            }

            if (_platform2 != null)
            {
                _platform2.BeginShutdown(
                    result =>
                    {
                        _platform2.EndShutdown(result);
                        shutdownCompleted.Set();
                    },
                        null);
                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Platform 1 shutdown did not complete.");
                _platform2 = null;
            }
        }

         private void EstablishCompleted(IAsyncResult result)
        {
            try
            {
                InstantMessagingCall call = result.AsyncState as InstantMessagingCall;
                call.EndEstablish(result);
            }
            catch (RealTimeException exception)
            {
                // TODO: Replace with exception handling code.
                Console.WriteLine("Call establish failed: {0}", exception.Message);
            }
            finally
            {
                // TODO: Add clean up code here.
            }
            m_call1Established.Set();
        }

        private void IncomingCallReceived(
            object sender,
            CallReceivedEventArgs<InstantMessagingCall> e)
        {
            _imCall2 = e.Call;
            _conversation2 = e.Call.Conversation;

            try
            {
                //e.Call.InstantMessagingFlowConfigurationRequested += this.FlowConfigurationRequested;

                // Accept the call. This will cause FlowConfigurationRequested to be raised.
                e.Call.BeginAccept(this.AcceptCompleted, e.Call);
            }
            catch (InvalidOperationException)
            {
                // Call got disconnected before it could be accepted
                // TODO: Replace with exception handling code.
                Console.WriteLine("Call was disconnected.");
            }
        }

        private void AcceptCompleted(IAsyncResult result)
        {
            try
            {
                InstantMessagingCall call = result.AsyncState as InstantMessagingCall;

                call.EndAccept(result);
            }
            catch (RealTimeException exception)
            {
                // TODO: Replace with exception handling code.
                Console.WriteLine("Call accept failed: {0}", exception.Message);
            }
            finally
            {
                // TODO: Add clean up code here.
            }
            m_call2Established.Set();
        }

       #region IMFlowConfigurationRequested

private void FlowConfigurationRequested(
    object sender,
    InstantMessagingFlowConfigurationRequestedEventArgs e)
{
    // Register to receive messages.
    e.Flow.MessageReceived += this.MessageReceived;

    // Register to receive composing state changes.
    e.Flow.RemoteComposingStateChanged += this.ComposingStateChanged;

    // Register to receive delivery notifications
    e.Flow.DeliveryNotificationReceived += this.DeliveryNotificationReceived;
}

private void ConversationTerminated(IAsyncResult result)
{
    // No need for exception handling since Terminate will not fail.
    Conversation conversation = result.AsyncState as Conversation;

    conversation.EndTerminate(result);
}
        #endregion ConversationTerminatedCallback

        [TearDown]
        public void TearDown()
        {
            AutoResetEvent shutdownCompleted = new AutoResetEvent(false);

            if (_imCall1 != null)
            {
                _imCall1.BeginTerminate(
                    result =>
                    {
                        _imCall1.EndTerminate(result);
                        shutdownCompleted.Set();
                    },
                    null);
                TestUtilities.Helper.AssertEvent(shutdownCompleted, "IM Call 1 did not shut down.");
                _imCall1 = null;
                _conversation1 = null;
            }

            if (_imCall2 != null)
            {
                _imCall2.BeginTerminate(
                    result =>
                    {
                        _imCall2.EndTerminate(result);
                        shutdownCompleted.Set();
                    },
                    null);
                #region TerminateConversation
_conversation1.BeginTerminate(
    this.ConversationTerminated,
    _conversation1 /*state*/);
                #endregion TerminateConversation

                TestUtilities.Helper.AssertEvent(shutdownCompleted, "IM Call 2 did not shut down.");
                _imCall2 = null;

                if (_conversation2 != null)
                {
                    _conversation2.BeginTerminate(
                        this.ConversationTerminated,
                        _conversation2 /*state*/);
                }
            }

            if (_endpoint1 != null)
            {
                _endpoint1.BeginTerminate(
                    result =>
                    {
                        _endpoint1.EndTerminate(result);
                        shutdownCompleted.Set();
                    },
                    null);

                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Endpoint 1 shutdown did not complete.");
                _endpoint1 = null;
            }

            if (_endpoint2 != null)
            {
                _endpoint2.BeginTerminate(
                    result =>
                    {
                        _endpoint2.EndTerminate(result);
                        shutdownCompleted.Set();
                    },
                    null);

                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Endpoint 2 shutdown did not complete.");
                _endpoint2 = null;
            }

            if (_platform1 != null)
            {
                _platform1.BeginShutdown(
                    result =>
                    {
                        _platform1.EndShutdown(result);
                        shutdownCompleted.Set();
                    },
                        null);
                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Platform 1 shutdown did not complete.");
                _platform1 = null;
            }

            if (_platform2 != null)
            {
                _platform2.BeginShutdown(
                    result =>
                    {
                        _platform2.EndShutdown(result);
                        shutdownCompleted.Set();
                    },
                        null);
                TestUtilities.Helper.AssertEvent(shutdownCompleted, "Platform 1 shutdown did not complete.");
                _platform2 = null;
            }
        }

         private void EstablishCompleted(IAsyncResult result)
        {
            try
            {
                InstantMessagingCall call = result.AsyncState as InstantMessagingCall;
                call.EndEstablish(result);
            }
            catch (RealTimeException exception)
            {
                // TODO: Replace with exception handling code.
                Console.WriteLine("Call establish failed: {0}", exception.Message);
            }
            finally
            {
                // TODO: Add clean up code here.
            }
            m_call1Established.Set();
        }

        private void IncomingCallReceived(
            object sender,
            CallReceivedEventArgs<InstantMessagingCall> e)
        {
            _imCall2 = e.Call;
            _conversation2 = e.Call.Conversation;

            try
            {
                //e.Call.InstantMessagingFlowConfigurationRequested += this.FlowConfigurationRequested;

                // Accept the call. This will cause FlowConfigurationRequested to be raised.
                e.Call.BeginAccept(this.AcceptCompleted, e.Call);
            }
            catch (InvalidOperationException)
            {
                // Call got disconnected before it could be accepted
                // TODO: Replace with exception handling code.
                Console.WriteLine("Call was disconnected.");
            }
        }

        private void AcceptCompleted(IAsyncResult result)
        {
            try
            {
                InstantMessagingCall call = result.AsyncState as InstantMessagingCall;

                call.EndAccept(result);
            }
            catch (RealTimeException exception)
            {
                // TODO: Replace with exception handling code.
                Console.WriteLine("Call accept failed: {0}", exception.Message);
            }
            finally
            {
                // TODO: Add clean up code here.
            }
            m_call2Established.Set();
        }

       #region IMFlowConfigurationRequested

private void FlowConfigurationRequested(
    object sender,
    InstantMessagingFlowConfigurationRequestedEventArgs e)
{
    // Register to receive messages.
    e.Flow.MessageReceived += this.MessageReceived;

    // Register to receive composing state changes.
    e.Flow.RemoteComposingStateChanged += this.ComposingStateChanged;

    // Register to receive delivery notifications
    e.Flow.DeliveryNotificationReceived += this.DeliveryNotificationReceived;
}

See Also

Reference

Conversation Class

Conversation Members

BeginTerminate Overload

Microsoft.Rtc.Collaboration Namespace