I use the Lync SDK 2013. When creating a new conversation (of any type, not audio/video only) my conversation_added
event triggers multiple times.
Having a permanent access to the LyncClient requires creating a timer check every second for a valid connection to the lync application.
I created a snippet that should work in WinForms applications
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();
}
private void connectionTimer_Tick(object sender, EventArgs e)
{
CheckConnection();
}
private void Conversation_Added(object sender, ConversationManagerEventArgs e)
{
System.Diagnostics.Process.Start("https://www.google.com/"); // open Browser window here
}
}
and you can see the full example here
I think the error appears because I always attach additional event listeners to the LyncClient. But I have to check the client connection on TrySetClient()
every second because the Skype application may get closed, crashed etc.
How can I fix this?