使用 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 客户端,并使用它 - 过程?