views:

112

answers:

4

I wrote a program in C# .NET, that needs to be run in the background. I mean it should have any user interface. Neither a GUI nor a CLI. It is not also a windows service(because it must run only after user has logged in).

It should just run in background. example of such programs are AdobeUpdater.exe , GoogleUpdater.exe etc.

A: 

Use Task Scheduler to run it on a schedule (which can be based on when user logs in). Or add it to the registry to run on startup.

HKLM\Software\Microsoft\Windows\CurrentVersion\Run
Sam
Thankyou. This is more of a tip than an answer to my query. In visual studio my program is either a `Windows Forms/WPF` (GUI) project or `CLI` project. Now, I don't want either. It should silently run in the background.
ThinkCentre
+4  A: 

Another option would be to create a Windows Application and set these two properties:

        this.WindowState = FormWindowState.Minimized;
        this.ShowInTaskbar = false;
BFree
ThinkCentre
@ThinkCentre: Try setting the Forms visibility property to false at design time. An application with a "hidden" form is your only option if you don't want to write it as a windows service, so work at getting this to work for you.
Binary Worrier
@BFree: +1 By the way :)
Binary Worrier
@ThinkCentre: If you set this at design time like @Binary suggested, or if you set this in the Form's constructor, you'll never see the form.
BFree
+2  A: 

You can create a Console application, and then change it's properties in the project settings to a Windows application (rather than console). Or you can create a Windows Forms application that ddoesn't actually create any forms.

Mystere Man
A: 

You might reconsider using a Windows service and having it monitor for logon/logoff events using the System.Management.ManagementEventWatcher class. This gives an example of a logoff event watcher: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0c1bded8-0cce-4260-bd28-4b4ffce0d27d.

ebpower