我使用 Lync SDK 2013。创建新对话(任何类型,不仅仅是音频/视频)时,我的conversation_added事件会触发多次。
永久访问 LyncClient 需要每秒创建一次计时器检查,以确保与 lync 应用程序的有效连接。
我创建了一个应该在 WinForms 应用程序中工作的片段
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
InitializeConnectionTimer();
}
private LyncClient client;
private ConversationManager conversationManager;
private Timer connectionTimer;
private bool networkAvailable;
private void InitializeConnectionTimer()
{
connectionTimer = new Timer
{
Interval = 1000
};
connectionTimer.Tick += connectionTimer_Tick;
connectionTimer.Start();
}
private void CheckConnection()
{
TrySetClient();
SetConversationManager();
}
private void TrySetClient()
{
client = null;
try
{
client = LyncClient.GetClient();
client.ClientDisconnected += Client_Disconnected;
client.StateChanged += Client_StateChanged;
}
catch (Exception)
{
}
}
private void SetConversationManager()
{
if (client != null)
{
conversationManager = client.ConversationManager;
conversationManager.ConversationAdded += Conversation_Added;
}
else
{
conversationManager = null;
}
}
private void Client_Disconnected(object sender, EventArgs e)
{
CheckConnection();
}
private void Client_StateChanged(object sender, ClientStateChangedEventArgs e)
{
CheckConnection();
}
你可以在这里看到完整的例子
https://pastebin.com/1tR3v8We
我认为出现错误是因为我总是将额外的事件侦听器附加到 LyncClient。但我必须TrySetClient()每秒检查客户端连接,因为 Skype 应用程序可能会关闭、崩溃等。
我怎样才能解决这个问题?
翻阅古今
相关分类