A
A
Alexander2015-05-23 09:55:06
Programming
Alexander, 2015-05-23 09:55:06

Windows Service or Application?

There is a task: the program must perform some action according to the established schedule.
There was a choice before me. Implement it as a Service or Application. Additionally, it will be necessary to make it possible to perform some settings (for example, a graph). You also need to notify the user about the operations performed.
Please advise what would be the best way to proceed in this case?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Stanislav Makarov, 2015-05-23
@Aleserche

It depends on the details. In particular, whether this action should be performed even if no user is logged in, or is it meaningless outside the user's context. If the first - then the service is generally better, however, additional efforts are needed to install it into the system, and, more importantly, you should not try to create windows from the service and generally interact with the UI - this is possible, but difficult and requires additional work. troubles. Therefore:
a) think about whether your application performs some kind of global task that does not depend on the user (a la defragmentation or, there, archiving). If yes, then:
b) evaluate whether it is possible to break your application into: the actual service that will perform a useful task; control panel - a regular desktop application that will interact with the service and change its settings and state;
c) assess whether you have the resources (time / money) to deal with additional subtleties (installing and running the service, features of writing the service (in the sharp you need to inherit from the library class), interaction between the UI control and the service);
d) if points a, b, c are true, then do it in accordance with them, if at least one is false, make a better desktop application.
In general, services are normally written on Sharp, I tried it, you can figure it out in a couple of days, including the simplest installation scripts.

S
Sumor, 2015-05-23
@Sumor

Write a console application and run it through AT or scheduler.
If you feel like it, you can issue the console as a service using SrvAny.exe or rewrite it as a service.

V
Vladimir Martyanov, 2015-05-23
@vilgeforce

The usual application, IMHO: there will be less trouble with both writing and launching.

R
Roman, 2015-05-23
@yarosroman

If according to the schedule, then the application + scheduler.

S
Sergey, 2015-05-25
@senal

In C#, you don't have to think ;)

static void Main(string[] args)
     {
            if (!Environment.UserInteractive)
            { 
                // running as service
                using (var service = new Service())
                        ServiceBase.Run(service);
            }
            else
            {
                      // run as console programm                      
                     DoWork();
            }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question