使用Lync SDK时,并排启动客户端,然后将其关闭 - 这会留下永不退出的孤立主机进程。我必须通过代码或任务管理器手动终止进程才能使其消失。 所以我在应用程序启动时使用代码。 当有多个进程同时运行时 - 我遇到其他问题并且还无限期地保留进程。
跟随所有MSDN如何在那里进行tos和示例,但仍然会发生相同的行为。这是我写的包装类中的一些代码。
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客户端,以及它 - 进程?
答案 0 :(得分:2)
我已经尝试在Client类周围编写一个包装器,它在我开始初始化Client之前获取当前时间,然后,在Client类初始化并生成新的Lync.exe进程之后,扫描活动Lync.exe在该开始时间之后处理并获取第一个并存储该pid。
然后,当我分解我的包装器类时,我取消了Client对象,然后使用存储的pid终止进程。这是一种可怕的肮脏黑客,但它运作得相当好。唯一的问题是如果桌面用户碰巧在短窗口中启动Lync而并排客户端正在旋转。
有趣的是,虽然文档表明您只能在并排模式下一次驱动一个Lync客户端,但此限制实际上只是每个进程。如果您在自己的子进程中生成每个并行Lync客户端并在子进程和主进程之间进行通信,则可以驱动任意数量的并行Lync客户端。