Edit

Share via


Conversation.BeginTerminate Method

Definition

Overloads

BeginTerminate(ConversationTerminateOptions, AsyncCallback, Object)

Begins an asynchronous operation to terminate the conversation.

BeginTerminate(AsyncCallback, Object)

Begins an asynchronous operation to terminate the conversation.

BeginTerminate(ConversationTerminateOptions, AsyncCallback, Object)

Begins an asynchronous operation to terminate the conversation.

public:
 IAsyncResult ^ BeginTerminate(Microsoft::Rtc::Collaboration::ConversationTerminateOptions ^ options, AsyncCallback ^ userCallback, System::Object ^ state);
public IAsyncResult BeginTerminate (Microsoft.Rtc.Collaboration.ConversationTerminateOptions options, AsyncCallback userCallback, object state);
member this.BeginTerminate : Microsoft.Rtc.Collaboration.ConversationTerminateOptions * AsyncCallback * obj -> IAsyncResult
Public Function BeginTerminate (options As ConversationTerminateOptions, userCallback As AsyncCallback, state As Object) As IAsyncResult

Parameters

options
ConversationTerminateOptions

Optional parameters to be applied when terminating the conversation. Can be null.

userCallback
AsyncCallback

The method to be called when the asynchronous operation is completed.

state
Object

A user-provided object that distinguishes this particular asynchronous operation from other asynchronous operations.

Returns

An IAsyncResult that references the asynchronous operation.

Exceptions

Thrown when the options has invalid diagnostics information..

Remarks

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

Applies to

BeginTerminate(AsyncCallback, Object)

Begins an asynchronous operation to terminate the conversation.

public:
 IAsyncResult ^ BeginTerminate(AsyncCallback ^ userCallback, System::Object ^ state);
public IAsyncResult BeginTerminate (AsyncCallback userCallback, object state);
member this.BeginTerminate : AsyncCallback * obj -> IAsyncResult
Public Function BeginTerminate (userCallback As AsyncCallback, state As Object) As IAsyncResult

Parameters

userCallback
AsyncCallback

The method to be called when the asynchronous operation is completed.

state
Object

A user-provided object that distinguishes this particular asynchronous operation from other asynchronous operations.

Returns

An IAsyncResult that references the asynchronous operation.

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


Remarks

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

Applies to