As I understand, you call long-term run the application which keeps executing as people login and logout and starts running after reboot. You can do so with the Windows Service, not with the UI application. (After all, it the users logout, there is no a desktop to he a UI parent; and who would interact with such application?)
So, you will need to have such UI started only when someone login. You can trigger executing such application form your service, in response to system events. To handle such events, your Windows Service application can use the class
Microsoft.Win32.SystemEvents
. To handle user login/logout events, you need to add handlers to some or all of the session events:
SessionEnded
,
SessionEnding
or
SessionSwitch
:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx[
^].
I would advise to make such UI application a thin client of your Windows Service application, as thin as possible — pure UI. All application logic, persistence, etc. — should better reside in the Windows Service application. The UI application can communicate to your Windows Service via IPC, which can be based on sockets, named pipes, classical remoting or WCF self-hosted by the Windows Service application.
—SA