David12123
David12123

Reputation: 119

C# change console application into service?

I have created a console program which is - a udp server that get data and then save it to a DB.

how can I make it run auto when windows is up?

do I need to change it to windows service? - if yes , how do I do it ?

Thanks ,

Upvotes: 0

Views: 172

Answers (2)

kunif
kunif

Reputation: 4360

If you are using the workstation version of Windows and it is okay for the program to run only while the user is logged on, register the shortcut for the program in the startup folder.

Alternatively, if you want to operate on server version of Windows or if you want to work without logging on workstation version, there is a means to register in Task Scheduler. It should be set up to run as a user with administrator privileges at system boot time. Starting an Executable on System Boot

If you can not do any of the above and you want to start as a service, you need to rework the program.

First of all, it is necessary to design by deleting interactive input/output functions such as console and dialog from the program. This is due to the feature of session 0 isolation of the service. Impact of Session 0 Isolation on Services and Drivers in Windows

Then design and create the program as a service. The explanation is here. Developing Windows Service Applications, How to: Create Windows Services

Upvotes: 0

nilsK
nilsK

Reputation: 4351

I have a similar setup. For developing purpose i start/debug a console program, while the software in production runs in a windows service.

Store your program logic into a YourProgramName.Bib project (class lib). Add a YourProgramName.Console project and start your Bib out of it. Now add a YourProgramName.WindowsService project and, also start your Bib out of it. That way you generate two *.exe files when compiling.

Use your YourProgramName.WindowsService.exe file for windows service setup.

Upvotes: 1

Related Questions