C# ZKemKeeper库中的实时事件处理程序在一段时间后停止响应设备活动

C# ZKemKeeper库中的实时事件处理程序在一段时间后停止响应设备活动,c#,C#,我创建了一个简单的Windows服务项目,使用ZKemKeeper库从指纹设备捕获实时事件。该服务在第一时间似乎工作正常,并且对设备中的事件响应良好。但我发现,在几分钟的不活动后,服务停止响应事件。我原以为是服务导致了问题,但WinForm应用程序中仍然存在问题,甚至SDK中包含的示例都显示了确切的问题 以下是Windows服务的代码: public partial class Service1 : ServiceBase { private System.Diagnostics.Eve

我创建了一个简单的Windows服务项目,使用ZKemKeeper库从指纹设备捕获实时事件。该服务在第一时间似乎工作正常,并且对设备中的事件响应良好。但我发现,在几分钟的不活动后,服务停止响应事件。我原以为是服务导致了问题,但WinForm应用程序中仍然存在问题,甚至SDK中包含的示例都显示了确切的问题

以下是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位版本的库。我使用.NETFramework4.0作为目标框架


Achmad Mulyadi

我和你有同样的问题,请尝试注销事件,然后每60秒重新注册一次,这对我来说很有效。我使用的是64位版本的og库,运行在windows 8.1中

        if (bIsConnected == true)
        {
            this.axCZKEM1.OnFinger -= new zkemkeeper._IZKEMEvents_OnFingerEventHandler(axCZKEM1_OnFinger);
            this.axCZKEM1.OnVerify -= new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
            this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
            this.axCZKEM1.OnFingerFeature -= new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(axCZKEM1_OnFingerFeature);
            this.axCZKEM1.OnEnrollFingerEx -= new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(axCZKEM1_OnEnrollFingerEx);

            iMachineNumber = 1;//In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
            if (axCZKEM1.RegEvent(iMachineNumber, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
            {
                this.axCZKEM1.OnFinger += new zkemkeeper._IZKEMEvents_OnFingerEventHandler(axCZKEM1_OnFinger);
                this.axCZKEM1.OnVerify += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
                this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                this.axCZKEM1.OnFingerFeature += new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(axCZKEM1_OnFingerFeature);
                this.axCZKEM1.OnEnrollFingerEx += new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(axCZKEM1_OnEnrollFingerEx);
            }
        }

如果您仍然没有找到答案,请创建计时器并将此代码放入其中

System.Windows.Forms.Application.DoEvents();

这将使ActiveX正常工作

您可以尝试在线程中添加此代码

System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler((object sender, System.Timers.ElapsedEventArgs e) => 
{
    string IPAddr = null;
    if (axCZKEM1.GetDeviceIP(iMachineNumber, IPAddr))
    {
        LogHelper.Log(LogLevel.Debug, "device " + IPAddr + ":" + port + " connect status is ok.");
    }
});
timer.Interval = 600000;// 10 minutes
timer.Enabled = true;

在到处寻找解决方案并多次阅读手册后,我发现我的问题是防火墙,因此请尝试禁用防火墙或为软件添加异常

我认为代码将在winform中工作,我不确定Win Service tho中是否工作,因为我避免在其中使用计时器。顺便问一下,你用的是什么设备?我是说品牌和系列?似乎这只发生在少数设备上。上周刚买了一个新的,在winform和windows服务中,即使不重新注册活动,它也能像charm一样工作。