Problem with Windows Service

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 4
Reputation: vic02 is an unknown quantity at this point 
Solved Threads: 0
vic02 vic02 is offline Offline
Newbie Poster

Problem with Windows Service

 
0
  #1
Nov 16th, 2006
Hello, I’m hoping someone at MS can help me.

I’ve created a C# Windows Service project whose service main function instantiates a class library that spawns a new thread to create a new process with which to launch osk.exe (the Windows on-screen keyboard). The purpose for creating this service is to have the on-screen keyboard appear immediately after startup (before the login screen) on a system that will have no keyboard hardware.

I had first built a test program (C# console application) to call the class library and test its functionality and it worked fine. Then I created the Service Project including its installer classes and installed the service with installutil. [Incidentally, all three projects—the class library that launches the osk in a new thread, the test console application, and the windows service—are in the same solution.]

Each time I manually start the service (using the MMC snap-in) I get the following message:
" The service <name> on Local Computer started and then stopped. Some services stop automatically if they have no work to do…"

I don’t understand what this means. The class library contains the necessary start and stop methods, and I copied the same code from the test program to the OnStart () method of the service class. Can anyone please help?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 1
Reputation: tatsky is an unknown quantity at this point 
Solved Threads: 0
tatsky tatsky is offline Offline
Newbie Poster

Re: Problem with Windows Service

 
0
  #2
Nov 24th, 2006
Hi There

I have experienced this issue with services that have thrown an exception during the Start() sequence of the Process.

To find out what is causing your service to bomb out, you need to debug the service. Are you using VS to build the service? If so you need to attach to the service thread when it starts, in order to step through the process.

The problem here being that there is no thread to attach to until the service has started, and your service is not getting started. The solution is as follows.

In your method
  1. static void Main(){}
add the line
  1. System.Diagnostics.Debugger.Launch();
. So your method looks like

  1. static void Main()
  2. {
  3. System.Diagnostics.Debugger.Launch();
  4. ServiceBase[] ServicesToRun;
  5.  
  6. ServicesToRun = new ServiceBase[] { new MyService1() };
  7. ServiceBase.Run(ServicesToRun);
  8. }

Then simply build and install your service. Then goto Service Manager and start the service. You should then see a diaogue pop up asking you what application you would like to use to debug the service. Select your VS which with the Service project open, and VS will then allow you to step through the service. You can then step through the OnStart method and see what is causing you the problem

Let me know if that helps

Tatsky
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: vic02 is an unknown quantity at this point 
Solved Threads: 0
vic02 vic02 is offline Offline
Newbie Poster

Re: Problem with Windows Service

 
0
  #3
Nov 27th, 2006
Tatsky,
Thank you for that tip!

It turns out that my service was having trouble finding an associated dll. But had I known you could launch the debugger from within the main function, it might have been easier to resolve.

Thanks again.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC