Windows Service General Questions
Today I built my first windows service in c#.
I have a few problems that I will be happy and thanksfull if you help me.
1) When I install my service, it is runing and everything, but it wont show up in Windows Task Manager. any one knows why?
2) If I am trying to put a system tray, I can't do it - because I cant put an icon. in window service ther开发者_如何学JAVAe is no System.Drawing.. what can I do about it?
3)
protected override void OnContinue()
{
//eventLog1.WriteEntry("In OnContinue.");
}
What does this "OnContinue" does?
I was not able to understand it.
Service Not Showing up in Windows Task Manager
I'm assuming that you are running on Vista/Windows 7 and that your service is not running as your account. Because of that, you need to say "show processes from all users" on the "Processes" tab of Task Manager and you should see your service then (probably running under one of the default Windows accounts).
You won't see your service in the "Applications" tab, services do not appear there.
Icon Tray for Windows Service
From Windows Vista on, a service is not allowed to interact with the desktop; even if you could still do this, which one do you interact with (there can be multiple users logged onto the machine with multiple desktops, think Terminal Server/multiple Remote Desktop Sessions)?
The way that you show an icon for the service is to create a program that communicates with your service (using something like WCF or Remoting) which is responsible for showing the icon in the tray.
Remember, your service more than likely doesn't need an icon in the tray, create a plugin for the Microsoft Management Console instead and communicate with the service through WCF/Remoting.
OnContinue
From the documentation for the OnContinue
method:
When implemented in a derived class, OnContinue runs when a Continue command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service resumes normal functioning after being paused.
Basically, if your service can be paused (not stopped) then this is called when the service is resumed.
1) If the service shows as running in the "Services" management console - then you should see a process in the Task Manager for the service. You will not see anything on the "Applications" tab - because services run in the background. However, in the "Processes" tab - you should see an entry for the executable file that you used to install the service.
3) The OnContinue()
method in a Windows service defines the actions that will occur when the service returns to the "Started" state from the "Paused" state.
精彩评论