ZKemKeeper 库中的实时事件处理程序没有响应

本文关键字:程序 响应 事件处理 实时 ZKemKeeper | 更新日期: 2024-10-26 03:15:52

我创建了一个Windows服务,通过使用Interop.zkemkeeper库从指纹设备获取实时事件。服务中计算机已成功连接,但服务未响应 OnAttTransactionEx 实时事件,这意味着在成功完全连接到计算机后,不会使用 OnAttTransactionEx 事件获取计算机出勤情况。我不知道问题出在哪里。

下面是 Windows Service 的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using zkemkeeper;
using System.Threading;
using System.Windows.Forms;
namespace WindowsService1
{
    public partial class Service1 : ServiceBase
    {
       // private System.Timers.Timer timer1 = null;
        string filePath = @"E:'file1.txt";
        bool connSatus = false;
        CZKEMClass axCZKEM1;
        public Service1()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            /* timer1 = new Timer();
             this.timer1.Interval = 10000;
             this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
             timer1.Enabled = true;
           */
              axCZKEM1 = new zkemkeeper.CZKEMClass();
              Thread createComAndMessagePumpThread = new Thread(() =>
              {
                  connSatus = axCZKEM1.Connect_Net("192.169.9.34", 4370);
                  using (StreamWriter writer = new StreamWriter(filePath, true))
                  {
                      writer.WriteLine("Machine is connected on" + "Date :" + DateTime.Now.ToString() + "status" + connSatus);
                      writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                  }
                  if (connSatus == true)
                  {
                      this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                      if (axCZKEM1.RegEvent(1, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                      {
                          this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                          using (StreamWriter writer = new StreamWriter(filePath, true))
                          {
                              writer.WriteLine("finger print Event is registered... ");
                              writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                          }
                      }
                  }
                 Application.Run();
              });
              createComAndMessagePumpThread.SetApartmentState(ApartmentState.STA);
              createComAndMessagePumpThread.Start();

        }
        public void axCZKEM1_OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode)
        {
           // if (OnAttTransactionEx != null) OnAttTransactionEx(sEnrollNumber, iIsInValid, iAttState, iVerifyMethod, iYear, iMonth, iDay, iHour, iMinute, iSecond, iWorkCode, axCZKEM1.MachineNumber, Tag);
            using (StreamWriter writer = new StreamWriter(filePath, true))
            {
                writer.WriteLine(" OnAttTrasactionEx Has been Triggered,Verified OK on" + "Date :" + "Enrollnumber" + sEnrollNumber + DateTime.Now.ToString());
                writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            } 
        }

        protected override void OnStop()
        {
           // timer1.Enabled = false;
            this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
            axCZKEM1.Disconnect();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            using (StreamWriter writer = new StreamWriter(filePath, true))
            {
                writer.WriteLine("Message is running on" + "Date :" + DateTime.Now.ToString());
                writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
        }
    }
}

ZKemKeeper 库中的实时事件处理程序没有响应

相应的版本是

protected override void OnStart(string[] args)
        {
              Thread createComAndMessagePumpThread = new Thread(() =>
              {
                  axCZKEM1 = new zkemkeeper.CZKEMClass();
                  connSatus = axCZKEM1.Connect_Net("192.169.9.34", 4370);
                  using (StreamWriter writer = new StreamWriter(filePath, true))
                  {
                      writer.WriteLine("Machine is connected on" + "Date :" + DateTime.Now.ToString() + "status" + connSatus);
                      writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                  }
                  if (connSatus == true)
                  {
                      this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                      if (axCZKEM1.RegEvent(1, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                      {
                          this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
                          using (StreamWriter writer = new StreamWriter(filePath, true))
                          {
                              writer.WriteLine("finger print Event is registered... ");
                              writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                          }
                      }
                  }
                 Application.Run();
              });
              createComAndMessagePumpThread.SetApartmentState(ApartmentState.STA);
              createComAndMessagePumpThread.Start();

        }