When working with the Lync SDK, starting up a client side-by-side, and then shutting it down -it leaves an orphaned host process that never quits. I have to manually kill the process by either code or task manager to make it go away. So i it with code in my application startup. When there are multiple processes running at the same time - i get other problems and also leave processes indefinitely.
Followed all the MSDN how tos and examples out there, but still the same behaviour occur. This is some code in a wrapper class i wrote.
public void Startup()
{
// Same thread should do the startup and shutdown right?
var _currentThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
this.KillRunningBackgroundProcesses("lync");
lyncClient = Microsoft.Lync.Model.LyncClient.GetClient(_sideBySide);
// Init lync (needed for side-by-side)
if (lyncClient.State == Microsoft.Lync.Model.ClientState.Uninitialized)
{
lyncClient.BeginInitialize(
(result) => { lyncClient.EndInitialize(result); }
, null);
}
// Wire events
lyncClient.StateChanged += lyncClient_StateChanged;
lyncClient.CredentialRequested += lyncClient_CredentialRequested;
lyncClient.SignInDelayed += lyncClient_SignInDelayed;
lyncClient.CapabilitiesChanged += lyncClient_CapabilitiesChanged;
lyncClient.ClientDisconnected += lyncClient_ClientDisconnected;
lyncClient.ConversationManager.ConversationRemoved += lyncClient_ConversationManager_ConversationRemoved;
lyncClient.ConversationManager.ConversationAdded += lyncClient_ConversationManager_ConversationAdded;
}
This is the shutdown code:
public void Shutdown()
{
// Same thread should do the startup and shutdown right?
var _currentThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
// Unwire events
lyncClient.StateChanged -= lyncClient_StateChanged;
lyncClient.CredentialRequested -= lyncClient_CredentialRequested;
lyncClient.SignInDelayed -= lyncClient_SignInDelayed;
lyncClient.CapabilitiesChanged -= lyncClient_CapabilitiesChanged;
lyncClient.ClientDisconnected -= lyncClient_ClientDisconnected;
lyncClient.ConversationManager.ConversationRemoved -= lyncClient_ConversationManager_ConversationRemoved;
lyncClient.ConversationManager.ConversationAdded -= lyncClient_ConversationManager_ConversationAdded;
//this.lyncClient.BeginShutdown(this.lyncClient.EndShutdown, someStateObject);
this.lyncClient.BeginShutdown(
(result) => { this.lyncClient.EndShutdown(result); }
, null );
this.lyncClient = null;
}
How do I gracefully exit/shutdown the Lync client, and with it - the process?