1

使用 Lync SDK 时,并排启动客户端,然后将其关闭 - 它会留下一个永不退出的孤立主机进程。我必须通过代码或任务管理器手动终止该进程以使其消失。所以我在我的应用程序启动中使用代码。当有多个进程同时运行时 - 我遇到其他问题并且也无限期地离开进程。

遵循所有 MSDN 如何操作和示例,但仍然发生相同的行为。这是我编写的包装类中的一些代码。

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

这是关闭代码:

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

如何优雅地退出/关闭 Lync 客户端,并使用它 - 过程?

4

1 回答 1

2

我已经在 Client 类周围编写了一个包装器,它在我开始初始化 Client 之前获取当前时间,然后在 Client 类初始化并产生新的 Lync.exe 进程之后,扫描活动的 Lync.exe 进程并在该开始时间之后获取第一个并存储该 pid。

然后,当我分解我的包装类时,我取消初始化 Client 对象,然后使用存储的 pid 终止进程。这是一种可怕的肮脏黑客,但它工作得相当好。唯一的问题是桌面用户碰巧在并行客户端启动时在短窗口中启动了 Lync。

有趣的事实是,尽管文档表明您一次只能在并排模式下驱动一个 Lync 客户端,但此限制实际上仅限于每个进程。如果您在自己的子进程中生成每个客户端并在子进程和主进程之间进行通信,则可以驱动任意数量的并排 Lync 客户端。

于 2015-04-16T13:01:28.620 回答