Blog Home  Home Feed your aggregator (RSS 2.0)  
kevin Mocha - Thursday, March 04, 2010
Bookmarks collected from web.
 
 Thursday, March 04, 2010

CLR and .NET Framework

The CLR is the runtime for executing managed code. C# is one of several managed
languages that get compiled into managed code. Managed code is packaged into an
assembly, in the form of either an executable file (an .exe) or a library (a .dll), along
with type information, or metadata.

Managed code is represented in Intermediate Language or IL. When the CLR loads
an assembly, it converts the IL into the native code of the machine, such as x86. This
conversion is done by the CLR’s JIT (Just-In-Time) compiler. An assembly retains

almost all of the original source language constructs, which makes it easy to inspect
and even generate code dynamically.

The CLR performs as a host for numerous runtime services. Examples of these services
include memory management, the loading of libraries, and security services.
The CLR is language-neutral, allowing developers to build applications in multiple
languages (e.g., C#, Visual Basic .NET, Managed C++, Delphi.NET, Chrome .NET,
and J#).

 

 

How the Garbage Collector Works:

The GC begins with its root object references, and walks the object graph, marking
all the objects it touches as reachable. Once this process is complete, all objects that
have not been marked are considered unused, and are subject to garbage collection.
Unused objects without finalizers are immediately discarded; unused objects with
finalizers are enqueued for processing on the finalizer thread after the GC is complete.
These objects then become eligible for collection in the next GC for the object’s
generation (unless resurrected).

 

The remaining “live” objects are then shifted to the start of the heap (compacted),
freeing space for more objects. This compaction serves two purposes: it avoids

memory fragmentation, and it allows the GC to employ a very simple strategy when
allocating new objects, which is to always allocate memory at the end of the heap.
This avoids the potentially time-consuming task of maintaining a list of free memory
segments.

 

If there is insufficient space to allocate memory for a new object after garbage
collection, and the operating system is unable to grant further memory, an
OutOfMemoryException is thrown.

 

Generational collection
The most important optimization is that the GC is generational. This takes advantage
of the fact that although many objects are allocated and discarded rapidly, certain
objects are long-lived and thus don’t need to be traced during every collection.
Basically, the GC divides the managed heap into three generations. Objects that have
just been allocated are in Gen0 and objects that have survived one collection cycle
are in Gen1; all other objects are in Gen2.

 

The large object heap
The GC uses a separate heap called the Large Object Heap (LOH) for objects larger
than a certain threshold (currently 85,000 bytes). This avoids excessive Gen0
collections—without the LOH, allocating a series of 16 MB objects might trigger a
Gen0 collection after every allocation.

The LOH is not subject to compaction, because moving large blocks of memory
during garbage collection would be prohibitively expensive. This has two
consequences:

1. Allocations can be slower
2. The LOH is subject to fragmentation

The large object heap is also nongenerational: all objects are treated as Gen2.

 

Concurrent and background collection

The GC must freeze (block) your execution threads for periods during a collection.
This includes the entire period during which a Gen0 or Gen1 collection takes place.
The GC makes a special attempt, though, at allowing threads to run during a Gen2
collection

 

Forcing Garbage Collection (not recommend)

GC.Collect()

 

A good guideline is to implement IDisposable yourself if any field in your class is assigned an object that implements IDisposable. (Such as System.Timers.Timer)(System.Threading.Timer is different)

 

Monitor the memory leaks: long memoryUsed = GC.GetTotalMemory (true);

 

Occasionally, it’s useful to hold a reference to an object that’s “invisible” to the GC
in terms of keeping the object alive. This is called a weak reference, and is implemented
by the System.WeakReference class.

 

One use for WeakReference is to cache large object graphs.
http://www.shafqatahmed.com/2008/01/weakreference-b.html

 

 

Asynchronous Methods

asynchronous programming model or APM

An asynchronous method aims never to block any thread, instead using a pattern of
returning with a callback.

 

The end goal of the APM is thread economy.

The purpose of asynchronous methods isn’t to
provide a convenient mechanism for executing a method in parallel with the caller;
it’s to optimize thread resources.

 

Here’s the golden rule of the APM: Make good use of the CPU, or exit with a callback!

 

The primary use for asynchronous methods is handling many potentially longrunning
concurrent requests—typically over slow network connections.

 

IAsyncResult BeginXXX (in/ref-args, AsyncCallback callback, object state);
return-type EndXXX (out/ref-args, IAsyncResult asyncResult);
public delegate void AsyncCallback (IAsyncResult ar);

 

To avoid blocking, you will nearly always call the EndXXX method from inside the
callback method. Callbacks always run on pooled threads.

 

image

 

http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls
http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx

Collections

ICollection Properties

image

image

IComparer
Copmare method

IEqualityComparer
GetHashCode, Equals

SortedList calss is a dictionary.

Race conditions and deadlocks

http://support.microsoft.com/kb/317723

A race condition occurs when two threads access a shared variable at the same time. The first thread reads the variable, and the second thread reads the same value from the variable. Then the first thread and second thread perform their operations on the value, and they race to see which thread can write the value last to the shared variable. The value of the thread that writes its value last is preserved, because the thread is writing over the value that the previous thread wrote.

A deadlock occurs when two threads each lock a different variable at the same time and then try to lock the variable that the other thread already locked. As a result, each thread stops executing and waits for the other thread to release the variable. Because each thread is holding the variable that the other thread wants, nothing occurs, and the threads remain deadlocked.

Thursday, March 04, 2010 7:57:29 PM UTC  #    Comments [0]    |   |  Trackback
 Wednesday, March 03, 2010
 Monday, March 01, 2010

http://learn.iis.net/page.aspx/140/understanding-the-built-in-user-and-group-accounts-in-iis-70/

In previous versions of IIS, we had a local account created at install time called IUSR_MachineName. The IUSR_MachineName account was the default identity used by IIS whenever anonymous authentication was enabled. This was used by both the FTP and HTTP services. 

There was also had a group called IIS_WPG, used as a container for all the application pool identities. We made sure all the appropriate resources on the system had the correct permissions set for the IIS_WPG group during IIS setup so that an administrator only needed to add their identity to that group when they created a new application pool account.

This model worked well, but had its drawbacks: the IUSR_MachineName account and IIS_WPG group were both local to the system it was created on. Every account and group within Windows is given a unique number called a SID (security identifier) that distinguishes it from other accounts. When an ACL is created only the SID is used. As part of our design in previous versions of IIS, we had included the IUSR_MachineName in the metabase.xml file so that if you tried to copy the metabase.xml from one machine to another, it would not work--the account on the other machine would have a different name.

In addition, you could not just 'xcopy /o' ACLs from one machine to another since the SIDs were different machine to machine. A work around was to use domain accounts--but that required adding an active directory to the infrastructure. The IIS_WPG group had similar issues with permissions. If you set ACLs on one machine's file system for IIS_WPG and tried to 'xcopy /o' those over to another machine, it would fail. The IIS team heard this feedback and improved this experience by using a built-in account and group in IIS 7.0.

A built-in account and group are guaranteed by the operating system to always have a unique SID. IIS 7.0 has taken this further and ensured the actual names used by the new account and group will never be localized. For example, regardless of the language of Windows you install, the IIS account name will always be IUSR and the group name will be IIS_IUSRS.

In summary, IIS 7.0 offers:

  • The IUSR built-in account replaces the IUSR_MachineName account
  • The IIS_IUSRS built-in group replaces the IIS_WPG group

Since the IUSR account is a built in account, it no longer needs a password. Logically, think of it as being the same as NETWORKSERVICE or LOCALSERVICE accounts. Both the new IUSR account and IIS_IUSRS group are discussed in greater depth in the sections below.

Monday, March 01, 2010 4:31:47 PM UTC  #    Comments [0]    |  Trackback
 Thursday, February 25, 2010
 Tuesday, February 23, 2010

http://msdn.microsoft.com/en-us/magazine/cc163403.aspx

http://www.codeproject.com/KB/office/MyContacts.aspx

http://www.outlookcode.com/news.aspx?id=22

http://msdn.microsoft.com/en-us/library/bb608610.aspx

http://msdn.microsoft.com/en-us/library/bb608615.aspx

http://msdn.microsoft.com/en-us/library/bb772084.aspx
http://social.msdn.microsoft.com/Forums/en-US/vsofficetools2008prerelease/thread/07144243-d59e-448e-a9b9-04ddbf9b58dc

Add a button to context menu
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/8cb73784-ce61-46e8-9241-25f67bdc5e99
http://social.msdn.microsoft.com/forums/en-US/vsto/thread/74e3fbaf-5806-4684-b410-65a0720386e8/

VSTO FAQ
http://social.msdn.microsoft.com/Forums/en/vsto/thread/31b1ffbf-117b-4e8f-ad38-71614437df59/?ffpr=0

FaceId Property http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/

Very Good Blog http://jake.ginnivan.net/tag/vsto/ 

Build Office-Based Solutions Using WPF, WCF, And LINQ http://msdn.microsoft.com/en-us/magazine/cc163292.aspx
Using WPF With VSTO & Office 2007 http://xamlcoder.com/cs/blogs/joe/archive/2007/07/17/using-wpf-with-vsto-office-2007.aspx

Programmatically Adding a Column to Your Outlook 2007 Inbox Table View http://blogs.msdn.com/bali_msft/archive/2008/11/04/programmatically-add-a-column-in-your-outlook-2007-inbox-table-view.aspx
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/d695b85f-39c3-4ff7-a528-54c029cdba8e/
http://social.msdn.microsoft.com/forums/en-US/vsto/thread/30ca71bf-b60c-4ed1-85de-0aa739f5ddd1/

Task Panel
http://msdn.microsoft.com/en-us/vbasic/cc338005.aspx
http://msdn.microsoft.com/en-us/library/bb296010.aspx
http://msdn.microsoft.com/en-us/library/bb608590.aspx
http://msdn.microsoft.com/en-us/library/aa942864%28VS.80%29.aspx

Tuesday, February 23, 2010 6:25:05 PM UTC  #    Comments [0]    |   |  Trackback
 Sunday, February 21, 2010
Sunday, February 21, 2010 7:19:58 AM UTC  #    Comments [0]    |  Trackback
 Friday, February 19, 2010
 Monday, February 01, 2010
Copyright © 2010 Kevin Mocha. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: