Need suggestion on replacing Windows Service by invisible WinForm Application
Asked Answered
C

2

1

I need a background application to support my client application, which should always run on the client machine regardless of the main client application is running or not.

Windows Service was my first choice but problems I faced with Windows Service were: ease of control over windows service through main client application, release and installation of patches to the windows service and troubleshooting if windows service fails to run.

So, I started thinking for alternatives to the Windows Service and found that a Windows Forms application with NO visible forms can do it for me. This invisible app should start with system startup and keep running all the time, doing all the work that a Windows Service would do. But before I go deeper into the development, I want to explore the pros and cons of this approach.

Any suggestions/comments on this approach?

Cosgrove answered 27/1, 2011 at 5:44 Comment(0)
E
1

Your requirements are more suited for windows service. Main advantage with windows service is that it will start as soon as system comes up, irrespective of anybody is logged into system or not.

To sort out deployment issues, you build your business logic into separate assembly and call the necessary function withing windows service. This way you can deploy just the modified assembly.

Winform application with invisible form will not serve the purpose. HTH

Electrochemistry answered 27/1, 2011 at 5:52 Comment(4)
I need windows service to interact with some files located in the Logged In user's App Data folder. I wonder if windows service can do this.Cosgrove
@Arpit: It seems you can access logged in user appdata folder. Not sure about its working, have a look at it: social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/…Ascription
As the linked thread indicates, a service has no knowledge of any users that may or may not happen to be logged in. My answer here gives the gory details. It doesn't really make any sense why you need a background application that runs all the time, even when a user is not logged in, to support your primary app. If I want to shut down your app, I should be able to do that definitively.Forgetful
@Arpit Khandelwal: you also said the service should start before a user logs in. How can you talk about "the Logged In user's App Data folder" at that time? How do you know which user will log in?Cortez
F
1

That's not possible. User-mode applications must be started by a user, and will not continue to run when that user logs off. That's the purpose of the SessionEnding event: to allow you to shut down your app gracefully when the user logs off or the computer is shutting down. You can't just start something at system startup and keep it running all the time.

You need a Windows Service for that. But you should be aware that under Windows Vista and later, a service cannot interact directly with the user. They run in a separate process and are restricted from displaying their own UI. It's not clear from the question exactly what your needs are, but this is an important limitation of a Windows Service that is worth considering. A proper design really shouldn't require this, but there are apparently a lot of people to whom this new, more secure behavior is a real surprise. I explain this in more detail in related answers to this question and this other question.

Forgetful answered 27/1, 2011 at 5:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.