Showing posts with label Interview series. Show all posts
Showing posts with label Interview series. Show all posts

Thursday, June 6, 2013

Interview Series: "What is a Windows Service and how does its lifecycle differ from a "standard" EXE?"

I came across a post on Scott Hanselman's website titled 'What Great .NET Developers Ought To Know (More .NET Interview Questions)' and the list of questions really caught my interest. So, I've decided to try and answer all of the questions. I'll probably have to look up a bunch, and some of the questions aren't really applicable to my field of work, but still - I'm expecting to learn quite a bit.


"What is a Windows Service and how does its lifecycle differ from a "standard" EXE?"

A windows service is a program that runs in the background, whereas a program runs mostly in the foreground. Again - go over to WikiPedia for more details. There are other differences as well: the way you start it, the way you install it etc.
Both can be created using Visual Studio 'file > new project' and there's not a whole lot to it. And - addressing the lifecycle part of the question: a service normally runs when windows starts and stop when windows shuts down. The application lifecycle however is normally controlled by the user, that can either start or stop it at will.

So when to opt for a service and not for an application? Well, when you need just that kind of behavior as described above. Something that always runs on the background and needs little or no user input. 

For example: I was working on a bookkeeping application in my former job. We needed to send out tax declarations to the authorities. We found a really cheap application that did just that - read from a pick-up folder and send it to the tax authorities. So - we decided to write a service that queried the database for declarations flagged to be sent out, every n minutes, and copy them to the pick-up location of the application.
This service started immediately when the machine booted, so it continued as the machine came back up.

Since the service was important however - we did ask our full service hosting provider to monitor the service state using nagios. As soon as that service went down, we would get a phone call. If the service is important to you - consider having that done!

Monday, June 3, 2013

Interview Series: "Describe the difference between a Thread and a Process?"

I came across a post on Scott Hanselman's website titled 'What Great .NET Developers Ought To Know (More .NET Interview Questions)' and the list of questions really caught my interest. So, I've decided to try and answer all of the questions. I'll probably have to look up a bunch, and some of the questions aren't really applicable to my field of work, but still - I'm expecting to learn quite a bit.


"Describe the difference between a Thread and a Process?"

A process is an instance of an application, which can run n-threads (depending on the OS). A thread being 'smallest sequence of programmed instructions that can be managed independently by an operating system scheduler'. For more detailed information, use the links below or use Google.

In terms of .NET namespaces, the processes are inside System.Diagnostics whereas the threading stuff is under System.Threading. I never really got why process is inside the diagnostics namespace, so If you know - place a comment.

A lot has changed in the .NET framework related to threading quite recently. In .NET 4 - the 'task' keyword was introduced and in 4.5 the 'async' and 'await' keywords were added to that. This is of course because processors are getting more and more cores. A nice video for getting up to speed with task/async/await is this one on YouTube:


One of the interesting points made in the video is that async does not mean multi-threaded. That was in eye-opener to me. What he also points out that if you have 8 cores and don't use multiple-threads, you're only using an eigth of the processor capacity at most.

Links:
- WikiPedia
- ProgrammerInterview.com