1

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?

imbageek
  • 609
  • 5
  • 18
  • How is this intended to be used because i assume it isn't the normal behaviour to let the process hang around indefinitely.. or is it? – imbageek Oct 02 '13 at 07:36
  • i have the same issue with windows 8 but it is randomly appeared. – Anas Jun 03 '14 at 14:48
  • I do the same as you, although I kill it after the shutdown as well. Everyone seems it have the same problem and there doesn't seem to be any nice solution atm.. – Shane Powell Nov 22 '14 at 22:36

1 Answers1

2

I've resorted to writing a wrapper around the Client class, which grabs the current time before I start to initialize the Client, then, after the Client class initializes and spawns off the new Lync.exe process, scans the active Lync.exe processes and grabs the first one after that start time and stores that pid.

Then, when I break down my wrapper class, I deinit the Client object, and then kill the process with the stored pid. It's kind of an awful dirty hack, but it works reasonably well. The only gotcha is if the desktop user happens to start Lync in the short window while the side-by-side client is spinning up.

Fun fact, although the documentation indicates that you can only drive one Lync client at a time in the side-by-side mode, this restriction is really only per-process. You can drive an arbitrary number of side-by-side Lync clients if you spawn each off in its own child process and communicate between the child processes and the main process.

EricRRichards
  • 474
  • 7
  • 20