我创建了一个简单的Windows服务项目,以使用ZKemKeeper库从指纹设备捕获实时事件。该服务似乎在第一时间正常工作,并且对设备中的事件做出了很好的响应。但是我发现,服务在几分钟不活动后停止响应该事件。我认为这是导致问题的服务,但是WinForm应用程序中仍存在问题,甚至SDK中包含的示例显示了确切的问题。ZKemKeeper库中的实时事件处理程序在一段时间后停止响应设备活动
下面是Windows服务代码:
public partial class Service1 : ServiceBase
{
private System.Diagnostics.EventLog eventLog1;
CZKEMClass myCZKEMClass;
public Service1()
{
InitializeComponent();
this.eventLog1 = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
this.eventLog1.Log = "MyLog";
this.eventLog1.Source = "MyLogSource";
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
this.ServiceName = "ZKemKeeperTestService";
}
protected override void OnStart(string[] args)
{
myCZKEMClass = new CZKEMClass();
Thread createComAndMessagePumpThread = new Thread(() =>
{
myCZKEMClass.Connect_Net("192.168.1.20", 4370);
if (myCZKEMClass.RegEvent(1, 65535))
{
myCZKEMClass.OnAttTransactionEx += new _IZKEMEvents_OnAttTransactionExEventHandler(myCZKEMClass_OnAttTransactionEx);
}
Application.Run();
});
createComAndMessagePumpThread.SetApartmentState(ApartmentState.STA);
createComAndMessagePumpThread.Start();
eventLog1.WriteEntry("Service Started");
}
protected override void OnStop()
{
eventLog1.WriteEntry("Service Stopped");
myCZKEMClass.OnAttTransactionEx -= new _IZKEMEvents_OnAttTransactionExEventHandler(myCZKEMClass_OnAttTransactionEx);
}
private void myCZKEMClass_OnAttTransactionEx(string EnrollNumber, int IsInValid, int AttState, int VerificationMethod, int Year, int Month, int Day, int Hour, int Minute, int Second, int WorkCode)
{
eventLog1.WriteEntry(EnrollNumber.ToString());
}
}
我不知道是什么问题的原因,我被困在那里。仅供参考,我正在使用在Windows 10中运行的库的64位版本。我使用.NET Framework 4.0作为目标框架。
艾哈迈德穆利阿迪
我认为代码将在winform中工作,我不知道在Win Service tho中,因为我避免在其中使用计时器。 Btw你用什么设备?我的意思是品牌和系列?似乎它只发生在很少的设备上。上周刚刚购买了一款新产品,即使没有重新注册该活动,Winform和Windows服务中的功能也很有魅力。 –