问题
Background: I have connected a window form application with a bio-metric attendance machine (ZKTeco K20 Model). It has connected but there is an issue with OnDisconncted event.
I have this code snippet, here onDisconnected event is registered but unfortunately, it is not triggering (whenever i switched off the device or unplug network cable).
public bool Connect_Net(string IPAdd, int Port)
{
if (objCZKEM.Connect_Net(IPAdd, Port))
{
//65535, 32767
//if (objCZKEM.RegEvent(1, 32767))//old
if (objCZKEM.RegEvent(1, 65535))
{
//MessageBox.Show("Connect_Net");
// [ Register your events here ]
// [ Go through the _IZKEMEvents_Event class for a complete list of events
objCZKEM.OnConnected += ObjCZKEM_OnConnected;
//objCZKEM.OnDisConnected += objCZKEM_OnDisConnected;
objCZKEM.OnDisConnected += new _IZKEMEvents_OnDisConnectedEventHandler(objCZKEM_OnDisConnected);
objCZKEM.OnEnrollFinger += ObjCZKEM_OnEnrollFinger;
objCZKEM.OnFinger += ObjCZKEM_OnFinger;
objCZKEM.OnAttTransactionEx += new _IZKEMEvents_OnAttTransactionExEventHandler(zkemClient_OnAttTransactionEx);
//objCZKEM.OnAttTransactionEx += new _IZKEMEvents_OnAttTransactionExEventHandler(objServerInteraction.zkemClient_OnAttTransactionEx);
objCZKEM.OnAlarm += OnAlarm;
objCZKEM.OnNewUser += OnNewUser;
objCZKEM.OnKeyPress += OnKeyPress;
}
return true;
}
return false;
}
The rest of the event like OnAttTransactionEx
executing fine but whenever my attendance device (Zketeco) turn off, it didn't fire objCZKEM_OnDisConnected
event. Do this event fire on device turn off (attendance machine).? Or I am registering it in wrong way?
Here is the link where I got this code with tutorial.
回答1:
objCZKEM.OnDisConnected is designed to clean up the resources while the device is soft-disconnected, but not the hard-disconnected. From your program, while you call the objCZKEM.disconnect, you would get the event triggered.
If the device is disconnected by wire, then no events will be triggered.
来源:https://stackoverflow.com/questions/52090851/zkemkeeper-ondisconnectedevent-is-not-firing-in-c-sharp