1

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.

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

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

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;
}

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 could not start the "MyServiceName" service on Local Computer.

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

Any help?

Community
  • 1
  • 1
Moussalam
  • 11
  • 1
  • 3
  • Step-by-step here: http://stackoverflow.com/questions/593454/easiest-language-for-creating-a-windows-service/593803#593803 – Matt Davis Oct 01 '12 at 13:07

2 Answers2

1

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.

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.

Murtuza Kabul
  • 6,438
  • 6
  • 27
  • 34
  • the triggered event raise from a device and the Service does not acquire user interaction at all. i need this service to stay connected to terminal to collect the sign in\out transactions done on the terminal. – Moussalam Oct 01 '12 at 10:43
  • It appears that the component AxBioBridgeSDK.AxBioBridgeSDKX is mfc component. If it is so, it will be expecting a message pump and a window which services do not have. Pls give me a bit more details on this component – Murtuza Kabul Oct 01 '12 at 12:25
  • Please also post some more code from the service so I can inspect the issue and give you proper answer. – Murtuza Kabul Oct 01 '12 at 12:29
0

this could be any number of things. check the event log for failed .net execution, it may provide more information about why it failed.

some things to consider when going from user app to windows service.

  1. the account which runs the app is different, so security permissions may be a factor
  2. windows services to have user interaction, where a desktop app does.
  3. if a service does not start quickly enough windows will automatically abort the process because it thinks there was a failure.

in short desktop != windows service != web app. Each has there own context, purpose, strengths and weaknesses.

Jason Meckley
  • 7,589
  • 1
  • 24
  • 45