Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Windows Service Main Method

I'm curious how exactly the Main() method works in a windows service as it relates to the Service Control Manager. When is it executed? How does it hook into the OS? Is it executed when a service is installed? I know it is executed when OnStart() is called by the SCM, OnStop() it's already running so we wouldn't execute it again.

If anyone knows a lot about this area and can elaborate I would appreciate it.

I am an expeirenced programmer, I don't need a description of what the Main Method does in general...just how it works in conjunction with windows services.

like image 810
Chris Kooken Avatar asked Dec 03 '10 22:12

Chris Kooken


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


1 Answers

When you use the Control Panel applet to tell the service to start the SCM launches the process; this causes the code inside of Main() to run. The ServiceBase.Run() line in the Main() method hooks the associated services into the SCM who then calls the OnStart() method for each of the services specified in the ServiceBase.Run() method call.

like image 173
Steve Ellinger Avatar answered Oct 08 '22 00:10

Steve Ellinger