- Describe the difference between a Thread and a Process?
A process is an executing instance of an application. For example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process.
It’s important to note that a thread can do anything a process can do. But since a process can consist of multiple threads, a thread could be considered a ‘lightweight’ process. Thus, the essential difference between a thread and a process is the work that each one is used to accomplish. Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.
Another difference between a thread and a process is that threads within the same process share the same address space, whereas different processes do not. This allows threads to read from and write to the same data structures and variables, and also facilitates communication between threads. Communication between processes – also known as IPC, or inter-process communication – is quite difficult and resource-intensive.
- What is the difference between an EXE and a DLL?
An exe runs in its own address space, Dll gets loaded into the 'hosting' process address space or a shared address space.
- What is a Windows Service and how does its lifecycle differ from an EXE?
Windows Service: Windows service is long running service. It will automatically start while booting.
Standard EXE: Where as for standard exe, we need to start it manually. Means it cannot be started unless you logon
- What is the GAC? What problem does it solve?
GAC=Global Assembly Cache, solves dll versioning (hell) problem. It's interesting to know how it solves the problem; each assembly is uniquely identified by 4 'things' major version number, minor version, and build and revision numbers. For each differing version, the GAC silently creates a subfolder based on a hash of these and places the assembly in it. From a user perspective it seems as if, we are moving the same file in one directory and it doesn't ask if it should overwrite the file!
- What is Web Gardening? How would using it affect a design?
If server has multiple processors and requests traffic is dividing accordingly that is called web gardening. If server is using external resources (like sql server, web services, logging) then it could be very useful.
- How can I throw an exception without losing the original stack trace information in .NET?
Use the "throw" keyword in place of "throw ex" to preserve the original stack trace information.
When you throw an exception using “throw ex” instead of “throw” you override the original stack trace with a new stack trace that starts from the throwing method. This can make tracking down the root causes of exceptions much more difficult. Take a look at the example below in order to see the differences in the stack traces depending on which option you use.
//Option 1 - Overrides original stack trace
throw ex;
//Option 2 - Keeps original stack trace
throw;
//Option 3 - Keeps original stack trace and adds additional information
throw new Exception("Additional information...", ex);
- Base Classes vs. Interfaces
An interface type is a specification of a protocol, potentially supported by many object types. Use base classes instead of interfaces whenever possible. From a versioning perspective, classes are more flexible than interfaces. With a class, you can ship Version 1.0 and then in Version 2.0 add a new method to the class. As long as the method is not abstract, any existing derived classes continue to function unchanged.
Because interfaces do not support implementation inheritance, the pattern that applies to classes does not apply to interfaces. Adding a method to an interface is equivalent to adding an abstract method to a base class; any class that implements the interface will break because the class does not implement the new method.
Interfaces are appropriate in the following situations:
- Several unrelated classes want to support the protocol.
- These classes already have established base classes (for example, some are user interface (UI) controls, and some are XML Web services).
- Aggregation is not appropriate or practical.
In all other situations, class inheritance is a better model.