I have created an application using C# 3.0.I need that application to start and run continuously whenever Windows starts.After setting up and installing the application this process should happen. Please give your suggestions to do this.
views:
71answers:
5Make it a Windows service, and have it start automatically. Or, if you only care when users are logged in, put it in the shared startup folder so it'll start for every user.
What about adding the program to the start-up folder in the install? When you create your set-up project, just add a shortcut to the output from the main program to the destination PC's start-up folder.
If you need an app to start when Windows starts and run continually, it should be a Windows Service. You won't be able to have GUI and Windows as a part of the same app/project, you'd need to write that separately and communicate with the Service.
If you want it to run continually and not stop, a plain Windows Forms app won't do it: the user can close it, of course. They can close a service too but you can configure in (on the Recovery tab) to restart if it 'fails' (is killed in Task Manager). They can still stop the service manually, though - but not as easily.
It's a project template built into Visual Studio. Depending on what your app is doing, it's usually best to create an instance of a Thread
object, and put your logic in a loop of sorts that executed on the new thread. From the OnStart
and OnStop
methods of the Service
thread itself, you can create the thread, or signal it to stop (or simply Abort
it).
By right-clicking on the service in the designer, you can 'Add Installer', which means if you run installutil
with the name of the application, the service will be installed and, if you set the correct properties on the Service and Installer, run automatically.
In terms of if you need a user interface - you'd have to come up with some way of the UI to talk to the service; you could use Named Pipes, Memory-Mapped Files, or you can use WCF (.NET 3.5+) with the Named Pipes/TCP provider, and call right into it.
For reference:
http://msdn.microsoft.com/en-us/library/aa984464(VS.71).aspx
Hope that helps.
What installation app are you using? Often they have functions for this built in.
If you want to do it in your c# code you will have to edit in the registry. Read this article. (I guess you also have to require administrator rights in the manifest to do that)
Use WindowService in that OnStart() {......} you will write code to start your application