Vous êtes sur la page 1sur 8

.

NET Developers
What Great .NET Developers Ought To Know

Everyone who writes code:

· Describe the difference between a Thread and a Process?

A process is a execution unit in it's own address space, a thread can't run on it's own - a
process has to 'fork' one. For example, IIS runs as a process but as http requests come in,
it spawns threads to handle each request.

A thread shares its address space with the other threads that belong to the same process.
• A process is an OS-level task or service. A thread runs "inside" a process
and may be virtual or simulated. Generally speaking, threads share
resources like memory, where processes each have their own separate
memory area, and need to take more elaborate steps to share resources.
• Another name for thread is "lightweight process" to distinguish it from the
"heavyweight" system processes.
• Diff Bet. Lighweight & heavyweight process
 [Short answer: threads are lightweight, programs (aka processes or
tasks) are heavyweight. -Alex]
• Lightweight and heavyweight processes refer the mechanics of a multi-
processing system.
• In a lightweight process, threads are used to divvy up the workload. Here
you would see one process executing in the OS (for this application or
service.) This process would posess 1 or more threads. Each of the
threads in this process shares the same address space. Because threads
share their address space, communication between the threads is simple
and efficient. Each thread could be compared to a process in a
heavyweight scenario.
• In a heavyweight process, new processes are created to perform the work
in parallel. Here (for the same application or service), you would see
multiple processes running. Each heavyweight process contains its own
address space. Communication between these processes would involve
additional communications mechanisms such as sockets or pipes.
• The benefits of a lightweight process come from the conservation of
resources. Since threads use the same code section, data section and OS
resources, less overall resources are used. The drawback is now you
have to ensure your system is thread-safe. You have to make sure the
threads don't step on each other. Fortunately, Java provides the necessary
tools to allow you to do this.
· What is a Windows Service and how does its lifecycle differ from a
"standard" EXE?

A windows service runs with it's own credential(different from the logged on user's
credentials). It doesn't stop if the logged on user logs off.

• Windows service is a application that runs in the background. It is


equivalent to a NT service.
• The executable created is not a Windows application, and hence you can't
just click and run it . it needs to be installed as a service, VB.Net has a
facility where we can add an installer to our program and then use a utility
to install the service. Where as this is not the case with standard exe

• A service opens before you even get to the login screen, whereas a
standard exe cannot open until after you have logged on.
• Windows Service applications are long-running applications that are ideal
for use in server environments. The applications do not have a user
interface or produce any visual output. Any user messages are typically
written to the Windows Event Log. Services can be automatically started
when the computer is booted. They do not require a logged in user in
order to execute and can run under the context of any user including the
system. Windows Services are controlled through the Service Control
Manager where they can be stopped, paused, and started as needed.
• Details please refer to:
http://www.developer.com/net/csharp/article.php/2173801

What is the maximum amount of memory any single process on Windows


can address? Is this different than the maximum virtual memory for the
system? How would this affect a system design?

• It depends on whether it's a 32-bit or 64-bit processing Windows. (You


would definitely know if it were a 64-bit machine.) I'm not entirely an
expert, but I do know a few things after encountering problems with this.
Supposedly, it's an integer like 2 raised to the 32nd power for 32-bit
systems and 2 raised to the 64th power for 64-bit systems. So, for 32-bit
systems, this is around 4Gb. Personal experience has supported this. The
main difference between the System RAM and virtual memory (hard-drive)
is the speed. Once you exhaust your available system RAM and start
using the hard-drive, speed will slow down incredibly while the hard-drive
is much slower to read and write to than RAM sticks. What kind of
behavior are you seeing with your PC? Are you watching the Task
Manager for clues?
What is the difference between an EXE and a DLL?

The main difference between an EXE and a DLL is the fact that an EXE contains
instructions for the processor and has an entry point for the execution to start. In this .Net
Drag and Drop world where most of the underlying tasks are taken care of for us, this is
sometimes hard to see. In the classes I teach, in order to focus on the the code and not the
bells and whistles, I often assign Console Applications for homework. The entry point for
a console application is the Sub Main() procedure. You can see this by going to project
properties and looking at the Startup object. Since a console application will create an
EXE, it needs to know where to start execution.

If we change the Application type from Console


Application to Class Library, you will notice that
the Startup object type now says <none>. This is
because a DLL cannot be executed(or
loaded)directly, it can only be called by another
process.

It is also interesting to note how this question relates to .Net Ought To Know #3. An EXE
runs in its own address space(out-of-process) while a DLL will run in the address space
of its host (in-process). If you wanted to dive deeper into this, you could load up both a
DLL and EXE in ILDasm.exe and look for the <entrypoint> marker in the EXE file.

• exe file is a excutable file which runs in a seperate process which is managed by
OS,where as a dll file is a dynamic link library which can be used in exe files and
other dll files.In .net frame work both are assemblies.

• fullname of .exe is Extensible Execute File


fullname of .dll is Dynamic Link Liberary
.exe use by End User like-Client
.Dll can not use by End User.
We can Run the .exe
but we can not Run the .Dll

• DLL: Can not run independently. Runs with EXE.


EXE: Can run independently.
• DLL: Takes up space in memory in processess' memory space, DLL is in-process
component.
EXE: Takes up space in memory separately, EXE is Out-process.
• DLL: Runs faster than exe.
EXE: Slower than DLL.
• DLL: error causes off the application.
EXE: can't.
• DLL: Doesn't have own main entry point, handled by other method(s).
EXE: Have own entry point, handled by OS.

• DLL is a in process component i.e. it runs in the same process space (means sever
n dll both share the same process space) whereas exe is a outof process
component means server n exe runs in its own process space.
• In case of dll any error in dll causes makes the application off whereas in case of
exe it cann't
• dll is faster than exe

An ActiveX Dll runs is an in process server running in the same memory space as the
client process.

An ActiveX Exe is an out of process server which runs in it's own separate memory
space.

Advantages of ActiveX Dll


-------------------------
1) An in-process component shares its client’s address space, so property and method
calls don’t have to be marshaled. This results in much faster performance.

Disadvantages of ActiveX Dll


----------------------------
1) If an unhandled error occurs it will cause the client process to stop operating.

Advantages of ActiveX Exe


-------------------------
1) The component can run as a standalone desktop application, like Microsoft Excel or
Microsoft Word, in addition to providing objects.
2) The component can process requests on an independent thread of execution, notifying
the client of task completion using events or asynchronous call-backs. This frees the
client to respond to the user.
3)If an error occurs the client processes can continue to operate.

Disadvantages of ActiveX Exe


----------------------------
1) Generally slower than an ActiveX dll alternative.

• "First we need to be clear that both "exe" and "dll" are fundamentally the same
but the difference lies in how windows interacts with them. "

When windows loads a dll, it runs the initialization code and then leaves it alone.
Functions in the dll are called if they are explicitly referenced by an application.
Another thing, when dll gets crashed it not only crashes itself but also the
application as the dll runs in the memory of the parent application.

When windows load an exe, the exe's initialization code is responsible for
creating what is called as "message pump", nothing but a program loop which
runs as long as the application is running. The message pump request messages
from the operating system. Windows keep track of the application as a separate
task. It allocates separate memory for both the exe and the application using that
exe. The memory area in which each exe runs is called "Process Space".

• Well the most obvious difference is that EXE files are used for launching an
application (it contains a startup function etc), whereas DLLs are loaded into an
application (ie they can't run by themselves).

• wo things: the extension and the header flag stored in the file.

• Both files are PE files. Both contain the exact same layout. A DLL is a library
and therefore can not be executed. If you try to run it you'll get an error about a
missing entry point. An EXE is a program that can be executed. It has an entry
point. A flag inside the PE header indicates which file type it is (irrelevant of file
extension). The PE header has a field where the entry point for the program
resides. In DLLs it isn't used (or at least not as an entry point).
• One minor difference is that in most cases DLLs have an export section where
symbols are exported. EXEs should never have an export section since they aren't
libraries but nothing prevents that from happening. The Win32 loader doesn't
care either way.
• Other than that they are identical. So, in summary, EXEs are executable programs
while DLLs are libraries loaded into a process and contain some sort of useful
functionality like security, database access or something.
· What is strong-typing versus weak-typing? Which is preferred? Why?

In strongly-typed programming languages you usually have to declare variables prior to


using them. Strong-typing is the strict enforcement of [type] rules. All types (int, short,
long, string) are know at compile time and are statically bound. So C# is a strongly-typed
language because variables must be assigned a type before you use them. If you came
from the ASP world then you will remember having to use either Javascript or VBScript.
Variables that you declare in either of those languages can hold any data type which
makes it weakly-typed.

But lets take this up a level. Instead to talking about programming languages, lets talk
about strongly-typed/weakly-typed objects. The DataSet object is a great example. If we
use a weakly-typed dataset, the developer needs to know the name of the table and the
name of the field being requested. Since we are just passing strings, this code will
compile and will not show any possible problems (like typing the name of the table
wrong) until run time.

string s = (string)
myDataSet.Tables["Customers"].Rows[0]["CustomerID"];

If our Dataset is Strongly-Typed, we are able to access the names of the tables and
columns directly. Any errors are caught at compile time.

string s = myDataSet.Customers[0].CustomerID;

I am not really going to argue which is better, I will leave that up to you. I will leave you
with this question though; would you rather catch your errors at compile time, or run-
time?

Strong typing implies that the types of variables involved in operations are associated to
the variable, checked at compile-time, and require explicit conversion; weak typing
implies that they are associated to the value, checked at run-time, and are implicitly
converted as required. (Which is preferred is a disputable point, but I personally prefer
strong typing because I like my errors to be found as soon as possible.)

Strong typing provides greater type safety. You might have specially heard it about
DataSets being strongly typed, where instead of referring columns as
datacolumns(index).value, you create an XML schema from which you make a dataset
derived class. Strong typing is preferred as there remains no type ambiguity. Another
example is, turning on Option strict in VB, where you have to do explicit type
casts.Instead of running into situation where you get a type that you did not expect and
try performing an operation on it, you go for strong typing so that such errors are caught
during compile time itself.

· Corillian's product is a "Component Container." Name at least 3


component containers that ship now with the Windows Server Family.

The answer to the question is not that tough so I thought we would go a little deeper and
talk about Components, Controls, and Containers Oh My!! (Sorry I couldn't resist). In the
.Net Framework, simply put, a component is a class that implements the
System.ComponentModel.IComponent interface or derives from a class that does. A
component is something that can be reused. C# is considered a component-oriented
language. Re-use is everything in component-oriented design. Putting together pre-tested
parts is faster and cheaper then coding it yourself. So to summertime, a component is any
class that directly or indirectly implements the IComponent Interface. A component can
be added to the toolbox and dragged and dropped onto a form.

A control on the other hand is a component that provides a UI. To do this you need to
implement System.Windows.Forms.Control OR System.Web.UI.Control. So a control is
basically a component that has visual properties.

This finally leads us to the answer to this question. You need a place to hold your
components and controls. This is done in a Container. A Container is a class that
implements the System.ComponentModel.IContainer interface (directly or indirectly).
Since this container holds your controls, it is easy to access the controls dynamically.

9 Private Class ControlWalker


10 Private mContainer As Object
11 Public Sub New(ByVal Container As Object)
12 Dim cControl As Control
13 If Container.haschildren Then
14 For Each cControl In Container.controls
15 'add this control to the controls collection
16 m_controls.Add(cControl)
17 If cControl.HasChildren Then
18 'This control has children, create another
19 'ControlWalk go visit each of them
20 Dim cWalker As New ControlWalker(cControl)
21 End If
22 Next cControl
23 End If
24 End Sub
25 End Class

· What is a PID? How is it useful when troubleshooting a system?


· How many processes can listen on a single TCP/IP port?

· What is the GAC? What problem does it solve?

Vous aimerez peut-être aussi