We have created on windows application, sometimes it is getting crashed, so it stopped from client end. Again user need to start the application manually. If we create windows service, incase the application crashes we can start from exe from service, can anyone help to start the exe from windows services
Related
I've created a simple socket application in which I have to open a socket receiver to listen for incoming messages on desktop. Problem is I need to be able to run the application as background service and I need to be able to start and stop the service from System Tray icon, for that I've created a windows forms application and added and I've created a windows service inside a windows forms application. On debug mode when I call the service code directly It's working fine. The service is installing and the OnStart method is being called. But when I try to start the application after building the project and running the .exe file I get the following error.
"Cannot start service from the command line or a debugger a windows service must first be installed. Then start with the server explorer"
And when I try to start the service manually from the windows services panel I get the following error.
"Error 1053: The service did not respond to the start or control request in a timely fashion".
This is the code used to install the service which is working fine.
AssemblyInstaller installer = GetInstaller(assembly)
installer.Install(state);
installer.Commit(state);
And this is the code for starting the service which is giving the error.
"Cannot start service from the command line or a debugger a windows service must first be installed. Then start with the server explorer"
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SocketService()
};
ServiceBase.Run(ServicesToRun);
Can anyone please help me with this. I need to create a single msi installation utility of the entire application. In which I need to install both the desktop application and the windows service. Where the desktop application can Start or Stop the service. Thanks.
This question already has answers here:
How to keep a .NET console app running?
(9 answers)
Closed 6 years ago.
I have developed a console app which must run in the background. The app must constantly check a database for new records. If new records are returned they are processed. My app as it currently stands uses while(true) to keep the application running. Is using a while loop the best solution.
A snippet of my code:
static void Main(string[] args)
{
while(true)
{
// Query db for new records
if(record_count > 0)
{
// Process the records
}
Thread.Sleep(500);
}
}
Create as Windows Service Application
What a Windows Service is ?
Enables you to create long-running executable applications that run in their own windows session.
Can be automatically started when the computer boots, can be paused and restarted without any user interaction.
Easily installable by running the command line utility InstallUtil.exe and passing the path to the service's executable file.
Why a Windows Service?
One of the most common requirements of some businesses is long-running scheduled jobs based on some time interval. For example: sending a newsletter everyday afternoon or send an email alert to the customer for every one hour.
So building a Windows Service could be one of the reliable solutions to do the goal that can do the required job in the behind the scenes without interfering others users on the same computer.
Please refer the link for step by step implementation -
http://www.c-sharpcorner.com/UploadFile/naresh.avari/develop-and-install-a-windows-service-in-C-Sharp/
Your approach to keep your console application continuously running is absolutely fine. Only thing is that you want to keep it running in background silently without user to know anything. Since a console app has a windowed UI (a command console) the user will keep seeing it. Here is what you can do to get rid of command console. Since you already have your console application with you, here is what you need to do :
Go to project properties -> Go to application Tab -> Change the Output type to Windows Application
Phew! Now your same console application will run without a command console and your code will keep running.
Creating a windows service will be too much of a kill for such a simple logic. Also installing a windows service is an extra overhead, though I am not aware of the deployment you are looking forward to for your application in production.
Better option would be to use Windows service that run in background.
Creating a Windows Service Application
Develop and Install a Windows Service in C#
Just google and you can find lots of article and tutorial on Windows Service.
There is no need to make your program running as a services. Services aren't for these small tasks. You should simply create a Windows (GUI, WinForms) application with a hidden window. Or, just don't create a window and just keep the Main running. Main would launch a thread and would itself wait for that thread.
A service has to be installed as a service and not all users would have permission to do that. It is complex task to have service, manage it, have security attributes settled et. al.
The hidden application can simply run in current user account (the service would be running in high-privilege SYSTEM or NETWORK account). Your application won't demand any privilege from current user - it just need SQL database/table read access.
Create a windows service which will check if your console app is running. If console app is down, then windows service will execute it again.
Don't write your console app's code into windows service. Because if it will start automatically at windows start up, then it may not work correctly as your console app.
I have a windows service installed on my PC and I have another application which checks whether the service is running and only if the service is running does my application open up. And my issue here is every time my system restarts the service which is set to startup Automatic (Delayed Start) goes into Starting mode and remains in that state like forever and I then have to use the task manager to end the service task and then start the service and it works fine from there on. How do I fix this issue. Thanks in advance
I have a Windows Service from which I have to run a process. However, that process requires admin privileges to run. Inside Process Explorer, I see that the service does run the process but the UI for that process does not appear up.
What am I missing here? How can this be rectified?
The services run in a separate session, with a separate desktop. Think of it as if the services where running in another remote desktop session. Anything with a GUI that you start from within a service will be shown in that hidden session, which cannot be accessed.
If you're working on Windows Vista or 7, services can't interact with desktop like windows XP and they can't open a window like ordinary windows applications. They default run as Local System account which is a fully privileged account.
I have a bat file which is installed as a service. I can run the service on a remote box. This service needs to launch another application. The launched application needs to be visible(run in foreground). Currently the launched application is running in background as the windows service is running in background. How can i make the windows service or both the windows service and the application that it launches run in foreground? I intend to manage the service with the ServiceController class in C#.
I think you should probably read
http://asprosys.blogspot.com.au/2009/03/allow-service-to-interact-with-desktop.html
Making a service to just launch another app is a real security issue, what if your other app gets replaced with something else do you have all the checks in your Service to ensure your app is the app you think it is.
A proper approach is to launch the second application in the user's session, while your Windows service app always runs in session 0.
The approach has been part of my discussion with #RaheelKhan under this thread,
How reliable is adding an application manifest to ensure elevated privileges across windows xp, vista and 7?
It requires proper understanding of Windows sessions, session isolation, and platform invoke.