Walkthrough: Sign Out of Lync with UI Suppressed (Lync 2010 SDK)
This topic demonstrates how a Lync 2010 API-based process signs a user out of Microsoft Lync 2010 and shuts Lync down when the Lync UI is suppressed. If such a process has initialized Lync 2010 using the steps described in Walkthrough: Sign In to Lync with UI Suppressed (Lync 2010 SDK), the process must run the code in this walkthrough before exiting. Failure to properly sign out and shut down Lync 2010 leaves it in an invalid state.
The steps in this walkthrough will sign a user out of Lync 2010 and shut it down. All other Lync 2010 API-based process on the local computer will lose their connection to Lync 2010 when it shuts down.
Prerequisites
Create a new Microsoft C# Windows Forms Application. For more information, see Writing Lync 2010 SDK Applications
Complete the tasks in Walkthrough: Sign In to Lync with UI Suppressed (Lync 2010 SDK).
Verify that the current process that is to shut down Lync 2010 is the same process that intitalized Lync 2010.
Sign Out and Shut Down Lync
Check the current state of LyncClient by reading the Client.State property. The client state must be ClientState.SignedIn. If any other state, you cannot sign the user out.
Call the BeginSignOut method to sign the user out of Lync.
Call the EndSignOut method.
Verify that Lync is in UI suppression mode. Read the InSuppressedMode property. If true, then the Lync UI is suppressed.
Verify that the current running process initialized Lync 2010. For information about tracking initialization, see Walkthrough: Sign In to Lync with UI Suppressed (Lync 2010 SDK).
Check the current state of LyncClient by reading the Client.State property. The client state must be ClientState.SignedOut. If any other state, you cannot shut down the client.
Call the BeginShutdown method. You must pass an instance of System.AsyncCallback into the method.
Call the EndShutdown within the callback method you passed in the prior step.
Examples
The following examples perform the steps in the walkthrough described previously.
Sign User Out
This example checks the state of LyncClient and signs the user out if the user is currently signed in.
/// <summary>
/// Handles "Sign Out" button click.
/// </summary>
/// <param name="sender">object. The button.</param>
/// <param name="e">EventArgs. The event data.</param>
private void btn_SignOut_Click(object sender, EventArgs e)
{
if (_lyncClient.State == ClientState.SignedIn)
{
_lyncClient.BeginSignOut(SignOutCallback, _asyncState);
}
}
Handle Sign Out Callback
The following example is called when the sign out operation completes.
/// <summary>
/// Called asynchronously by client instance after Signout()
/// </summary>
/// <param name="signedOutClient">LyncClient. Client signed out</param>
/// <param name="AsyncOp">IAsynchronousOperation. Asynchronous state</param>
private void SignOutCallback(IAsyncResult ar)
{
_lyncClient.EndSignOut(ar);
}
Shut Down Lync
The following example shuts Lync down.
/// <summary>
/// Handles the FormClosed event
/// </summary>
/// <param name="sender">object. The closed Windows Form object.</param>
/// <param name="e">FormClosedEventArgs. The event data</param>
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (_lyncClient.InSuppressedMode == true)
{
//_ThisInitializedLync is part of application state and is
//a class Boolean field that is set to true if this process
//initialized Lync.
if (_ThisInitializedLync == true)
{
if (_lyncClient.State == ClientState.SignedOut)
{
_lyncClient.BeginShutdown(shutdowncallback, null);
}
}
}
}
Handle Shut Down Callback
The following example is called when the shut down operation completes.
private void shutdowncallback(IAsyncResult ar)
{
if (ar.IsCompleted == true)
{
_lyncClient.EndShutdown(ar);
}
}