I have next code:
using AsterNET.Manager;
using AsterNET.Manager.Event;
private ManagerConnection manager;
private bool StartManager()
{
manager = new(
Properties.Resources.amiAddress,
Int32.Parse(Properties.Resources.amiPort),
Properties.Resources.amiLogin,
Properties.Resources.amiPass
);
manager.ConnectionState += new ConnectionStateEventHandler(ConnectionState);
try
{
manager.Login();
return true;
}
catch
{
return false;
}
}
private void ConnectionState(object sender, ConnectionStateEvent e)
{
if (manager.IsConnected())
{
MessageBox.Show("on");
notifyIcon1.Icon = Properties.Resources.phone_on;
}
else
{
MessageBox.Show("off");
notifyIcon1.Icon = Properties.Resources.phone_off;
}
}
Asterisk is in the local net. When I break the connection (pull out the cable), manager.IsConnected() is true, but must be false. I don't understand this behavior. How I can check connection?
I seem to have found a particular solution for my case. The fact is that it seems that when the ConnectionStateEvent event fires, the state of the ConnectionManager does not change immediately. Why this happens I did not understand. But when adding a delay, the IsConnected method began to work correctly.