Windows服务中的事件处理 [英] events handling in windows services

查看:213
本文介绍了Windows服务中的事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用C#框架4.0创建Windows服务的新功能,我已经制作了一个使用DLL文件连接到指纹考勤终端的Windows应用程序。

I am new in creating windows services using C# framework 4.0, i have made a windows application that uses a DLL files to connect to a finger print attendance terminal.

但我很困惑如何将Windows应用程序转换为Windows服务。

but i am confused in how to convert windows app to windows services.

因为我遵循教程,我可以运行和安装一个简单的服务。但是如何在Windows服务中添加新事件

as i followed the tutorials i can run and install a simple services. but how to add new event in windows service

所以首先我在项目中添加对我的DLL文件的引用。
second我在InitializeComponent方法中添加了这个代码

so first i add reference to my DLL file in project. second i added this code in the InitializeComponent method

    private void InitializeComponent()
    {  
        this.ServiceName = "MyService";
        AxBioBridgeSDK.AxBioBridgeSDKX MyBio = new AxBioBridgeSDK.AxBioBridgeSDKX();

        MyBio.OnAttTransaction += new AxBioBridgeSDK.IBioBridgeSDKXEvents_OnAttTransactionEventHandler(this.axBioBridgeSDKX1_OnAttTransaction); // this is the event handler function
    }

    #endregion
    private AxBioBridgeSDK.AxBioBridgeSDKX MyBio;
}

OnStart()我添加代码打开与终端的连接。
在我安装该服务并尝试运行后,我收到此错误:

and in the OnStart() i add code to open connection with terminal. after i install the service and try to run it i get this error :


Windows无法启动MyServiceName服务在本地计算机上。

Windows could not start the "MyServiceName" service on Local Computer.

错误1053:服务没有及时响应启动或控制请求。

Error 1053: The service did not respond to the start or control request in a timely fashion.

任何帮助?

推荐答案

Windows服务不是要处理用户界面事件。它们被设计为在单独的内存空间和不同的凭据中运行。通常他们不要求用户登录。

Windows services are not meant to handle user interface events. They are designed to run in a separate memory space and with different credentials. Usually they don't require the user to be logged in.

您所获得的错误是因为您的服务启动功能不正常,服务是一旦你开始就立即停止。

The error you are getting is due the reason that your services start function is not properly behaving and the services is stopping immediately once you start it.

调试服务需要一些不同的技术,然后调试Windows应用程序。您需要首先安装该服务,并使用服务管理器启动它,以便您可以对其进行调试。

Debugging service requires some different techniques then debugging windows application. You need to install the service first and start it using service manager so that you can debug it.

这篇关于Windows服务中的事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆