Try this:
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");
Put the code inside Start method of the service. You need to add a reference to System.Windows.Form library.
But this SDK seems have another problem, the event will stop working after couple mins if you let the service idle (same thing happened to WinForms too). I'm not sure if it's only me who had this problem, but the code samples gave me same result.