<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Shimon Krokhmal's blog - .Net</title>
    <link>http://www.krokhmal.com/</link>
    <description>medium : .NET | JavaScript | Secure coding | Databases | Sql Server | Oracle | CodeSmith | SPS | Life</description>
    <language>en-us</language>
    <copyright>Shimon Krokhmal</copyright>
    <lastBuildDate>Wed, 17 Oct 2007 10:15:49 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>Shimonkr@gmail.com</managingEditor>
    <webMaster>Shimonkr@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=68f84cff-ecab-4c94-ac9d-ce2ed3428e87</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,68f84cff-ecab-4c94-ac9d-ce2ed3428e87.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,68f84cff-ecab-4c94-ac9d-ce2ed3428e87.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=68f84cff-ecab-4c94-ac9d-ce2ed3428e87</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As part of a development process, deployment, if handled wrong, may consume much of
your precius time.<br />
my goal is to automate as much as possible the deployment process.
</p>
        <p>
I've read recently a post by <a href="http://blogs.madtechnology.net/blogs/chris/default.aspx">Chris
Burrows</a>, which talks about "<a href="http://blogs.madtechnology.net/blogs/chris/archive/2006/11/22/665.aspx">Setting
Up Your Build Environment with TFS</a>".<br />
I strongly suggest paying him a visit, it contains many insights about the process.
</p>
        <p>
he talks about :<br /></p>
        <li>
Continuous Integration 
</li>
        <li>
Dependency Replication 
</li>
        <li>
Automated Unit Testing and Code Coverage 
</li>
        <li>
Automated Deployment 
</li>
        <li>
Build Verification Tests 
</li>
        <li>
Deployment Verification Tests 
</li>
        <p>
this post is more as a question than just plain info,<br />
How do you practice these subjects ?<br />
Which tools/templates/methodologies do you use to elevate your process ?
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=68f84cff-ecab-4c94-ac9d-ce2ed3428e87" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Automating development process</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,68f84cff-ecab-4c94-ac9d-ce2ed3428e87.aspx</guid>
      <link>http://www.krokhmal.com/2007/10/17/AutomatingDevelopmentProcess.aspx</link>
      <pubDate>Wed, 17 Oct 2007 10:15:49 GMT</pubDate>
      <description>&lt;p&gt;
As part of a development process, deployment, if handled wrong, may consume much of
your precius time.&lt;br&gt;
my goal is to automate as much as possible the deployment process.
&lt;/p&gt;
&lt;p&gt;
I've read recently a post by&amp;nbsp;&lt;a href="http://blogs.madtechnology.net/blogs/chris/default.aspx"&gt;Chris
Burrows&lt;/a&gt;, which talks about "&lt;a href="http://blogs.madtechnology.net/blogs/chris/archive/2006/11/22/665.aspx"&gt;Setting
Up Your Build Environment with TFS&lt;/a&gt;".&lt;br&gt;
I strongly suggest paying him a visit, it contains many insights about the process.
&lt;/p&gt;
&lt;p&gt;
he talks about :&lt;br&gt;
&lt;/p&gt;
&lt;li&gt;
Continuous Integration 
&lt;li&gt;
Dependency Replication 
&lt;li&gt;
Automated Unit Testing and Code Coverage 
&lt;li&gt;
Automated Deployment 
&lt;li&gt;
Build Verification Tests 
&lt;li&gt;
Deployment Verification Tests 
&lt;/li&gt;
&lt;p&gt;
this post is more as a question than just plain info,&lt;br&gt;
How do you practice these subjects ?&lt;br&gt;
Which tools/templates/methodologies do you use to elevate your process ?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=68f84cff-ecab-4c94-ac9d-ce2ed3428e87" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,68f84cff-ecab-4c94-ac9d-ce2ed3428e87.aspx</comments>
      <category>.Net</category>
      <category>Architectural solutions</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=1b5f5757-3a61-470f-be80-ac10a116147d</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,1b5f5757-3a61-470f-be80-ac10a116147d.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,1b5f5757-3a61-470f-be80-ac10a116147d.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1b5f5757-3a61-470f-be80-ac10a116147d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft is going to publish it's source of .Net framework under a <a href="http://www.microsoft.com/resources/sharedsource/licensingbasics/referencelicense.mspx">referance
licience</a> ,<br />
According to <a href="http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx">this
post of scott Gu</a> , i will be intergated in the new Visual studio 2008.
</p>
        <font face="arial" size="2">
          <p>
            <a href="http://www.hanselminutes.com/default.aspx?showid=101" target="_blank">check
out this Podcast</a> that <a href="http://www.hanselman.com/blog/" target="_blank">Scott
Hanselman</a> and <a href="http://blogs.msdn.com/sburke/" target="_blank">Shawn Burke</a> recently
recorded.<br />
Not sure what this move will cause, but it's defenatly sounds cool.
</p>
          <p>
maybe it will kill the Mono-project, or maybe give him some strong boost, time will
show...
</p>
        </font>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=1b5f5757-3a61-470f-be80-ac10a116147d" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>.Net framework - open source</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,1b5f5757-3a61-470f-be80-ac10a116147d.aspx</guid>
      <link>http://www.krokhmal.com/2007/10/06/NetFrameworkOpenSource.aspx</link>
      <pubDate>Sat, 06 Oct 2007 21:21:42 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft is going to publish it's source of .Net framework under a &lt;a href="http://www.microsoft.com/resources/sharedsource/licensingbasics/referencelicense.mspx"&gt;referance
licience&lt;/a&gt;&amp;nbsp;,&lt;br&gt;
According to &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx"&gt;this
post of scott Gu&lt;/a&gt;&amp;nbsp;, i will be intergated in the new Visual studio 2008.
&lt;/p&gt;
&lt;font face=arial size=2&gt; 
&lt;p&gt;
&lt;a href="http://www.hanselminutes.com/default.aspx?showid=101" target=_blank&gt;check
out this Podcast&lt;/a&gt; that &lt;a href="http://www.hanselman.com/blog/" target=_blank&gt;Scott
Hanselman&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/sburke/" target=_blank&gt;Shawn Burke&lt;/a&gt; recently
recorded.&lt;br&gt;
Not sure what this move will cause, but it's defenatly sounds cool.
&lt;/p&gt;
&lt;p&gt;
maybe it will kill the Mono-project, or maybe give him some strong boost, time will
show...
&lt;/p&gt;
&lt;/font&gt;&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=1b5f5757-3a61-470f-be80-ac10a116147d" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,1b5f5757-3a61-470f-be80-ac10a116147d.aspx</comments>
      <category>.Net</category>
      <category>Microsoft</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=83234cdf-66bc-4a38-aad0-b9a1454af394</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,83234cdf-66bc-4a38-aad0-b9a1454af394.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,83234cdf-66bc-4a38-aad0-b9a1454af394.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=83234cdf-66bc-4a38-aad0-b9a1454af394</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
a little background to that question,<br />
in the last week I'm doing some sort of a job interviews marathon, being asked for
some quite interesting questions (most of them are really simply OPP questions).<br />
but this one caught me off guard, wouldn't expect this one as a pre-interview question
over the phone.
</p>
        <p>
so, how does this strange creature work (which most of us using it without even knowing
what it does behind) ?
</p>
        <p>
in contrast to regular method calling, the virtual method calling isn't called directly,
instead it uses the "<a href="http://www.answers.com/topic/virtual-method-table">Virtual
Functions Table</a>". (C# compiler implements it with VFT, other compilers may
implement it via binary trees)<br />
in short, it uses pointers to functions table, to map the call to the right method.<br />
lets take a look at an example :<br /></p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Father<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">virtual</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> foo()<br />
{<br />
Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"string
from the father"</span>);<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">virtual</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> foo2()<br />
{<br />
Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"foo2
string from the father"</span>);<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">internal</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> boo()<br />
{<br />
Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"father
says boo"</span>);<br />
}<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Son
: Father<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> foo()<br />
{<br />
Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"string
from the son"</span>);<br />
}<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> moo()<br />
{<br />
Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"son
says moo"</span>);<br />
}<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> faaBase()<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.foo();<br />
}<br />
}</span>
        </p>
        <p>
we have 2 classes ,son derives from the father, and overrides one of his virtual
methods.<br /><br /></p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Father
f <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Father();<br />
Son s <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Son();<br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Father calls<br /></span><font color="#008000">// Virtual method call</font><br />
f.foo();<br />
f.foo2();<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <br />
            <font color="#008000">// Non virtual method calls</font>
            <br />
f.boo();<br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Son calls<br /></span><font color="#008000">// Virtual method call<br /></font>s.foo();<br /><br /><font color="#008000">// Non virtual method calls<br /></font>s.boo();<br />
s.moo();</span>
        </p>
        <p>
what really happens behind ?<br />
lets view a part of the disassembly code<br /></p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Virtual method call</span>
            <br />
s.foo();<br />
00000065 mov ecx,esi 
<br />
00000067 mov eax,dword ptr [ecx] 
<br /><strong>00000069 call dword ptr [eax+38h]</strong><br />
0000006c nop 
<br /><br />
s.foo2();<br />
0000006d mov ecx,esi 
<br />
0000006f mov eax,dword ptr [ecx] 
<br /><strong>00000071 call dword ptr [eax+3Ch]</strong><br />
00000074 nop 
<br /><br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Non virtual method calls</span><br />
s.boo();<br />
00000075 mov ecx,esi 
<br />
00000077 cmp dword ptr [ecx],ecx 
<br /><strong>00000079 call FFAB30A0</strong><br />
0000007e nop 
<br /><br />
s.moo();<br />
0000007f mov ecx,esi 
<br />
00000081 cmp dword ptr [ecx],ecx 
<br /><strong>00000083 call FFAB3158</strong><br />
00000088 nop </span>
        </p>
        <p>
          <br />
we can see clearly that the non virtual call has a direct calling to the function
(a hard coded address),<br />
whereas the virtual method calling points to the virtual method table that resides
in the Son object.<br />
lets take a look on that table :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EEClass:
00a21370<br />
Module: 00a22c24<br />
Name: VTF.Son<br />
mdToken: 02000004 (E:\PROJECTS\vtf 2005\VTF\VTF\bin\Debug\VTF.exe)<br />
BaseSize: 0xc<br />
ComponentSize: 0x0<br />
Number of IFaces <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> IFaceMap:
0<br />
Slots <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> VTable:
9<br />
--------------------------------------<br />
MethodDesc Table<br />
Entry    MethodDesc JIT     Name<br />
7934cdcc 79137ab8    PreJIT System.Object.ToString()<br />
7934bba0 79137ac0    PreJIT System.Object.Equals(System.Object)<br />
7934bb90 79137ad8    PreJIT System.Object.GetHashCode()<br />
793424c0 79137ae0    PreJIT System.Object.Finalize()<br /><strong>00a231b8 00a23140    JIT    VTF.Son.foo()<br />
00a23100 00a23088    JIT    VTF.Father.foo2()</strong><br />
00a231c8 00a23148    NONE   VTF.Son.moo()<br />
00a231d8 00a23150    NONE   VTF.Son.faaBase()<br />
00a231e8 00a23158    JIT    VTF.Son..ctor()</span>
        </p>
        <p>
 
</p>
        <p>
we can see a couple of things from this table:
</p>
        <ul>
          <li>
VT lists all the methods the son object holds 
</li>
          <li>
VT lists the virtual functions of the father that are virtual 
</li>
          <li>
When the son object overrides one of the virtual methods that the father implements, 
<br />
the father method entry is being replaced by the new son method (line 5 at the table
- Son.foo()) 
</li>
          <li>
the VT does not list father method that are not virtual.</li>
        </ul>
        <p>
actually the Son.moo() method looks a little unnecessary in the VT due to the
fact that the function is not virtual and will be addressed directly and not by the
VT.
</p>
        <p>
in conclusion, think twice before you declare a method as virtual, because it contains
some performance hit
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=83234cdf-66bc-4a38-aad0-b9a1454af394" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Virtual functions under the hood</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,83234cdf-66bc-4a38-aad0-b9a1454af394.aspx</guid>
      <link>http://www.krokhmal.com/2007/07/21/VirtualFunctionsUnderTheHood.aspx</link>
      <pubDate>Sat, 21 Jul 2007 13:39:10 GMT</pubDate>
      <description>&lt;p&gt;
a little background to that question,&lt;br&gt;
in the last week I'm doing some sort of a job interviews marathon, being asked for
some quite interesting questions (most of them are really simply OPP questions).&lt;br&gt;
but this one caught me off guard, wouldn't expect this one as a pre-interview question
over the phone.
&lt;/p&gt;
&lt;p&gt;
so, how does this strange creature work (which most of us using it without even knowing
what it does behind) ?
&lt;/p&gt;
&lt;p&gt;
in contrast to regular method calling, the virtual method calling isn't called directly,
instead it uses the "&lt;a href="http://www.answers.com/topic/virtual-method-table"&gt;Virtual
Functions Table&lt;/a&gt;". (C# compiler implements it with VFT, other compilers&amp;nbsp;may
implement it via binary trees)&lt;br&gt;
in short, it uses pointers to functions table, to map the call to the right method.&lt;br&gt;
lets take a look at an example :&lt;br&gt;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Father&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;virtual&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; foo()&lt;br&gt;
{&lt;br&gt;
Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"string
from the father"&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;virtual&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; foo2()&lt;br&gt;
{&lt;br&gt;
Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"foo2
string from the father"&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;internal&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; boo()&lt;br&gt;
{&lt;br&gt;
Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"father
says boo"&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Son
: Father&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; foo()&lt;br&gt;
{&lt;br&gt;
Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"string
from the son"&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; moo()&lt;br&gt;
{&lt;br&gt;
Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"son
says moo"&lt;/span&gt;);&lt;br&gt;
}&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; faaBase()&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.foo();&lt;br&gt;
}&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
we have 2 classes ,son&amp;nbsp;derives from the father, and overrides one of his virtual
methods.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Father
f &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Father();&lt;br&gt;
Son s &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Son();&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Father calls&lt;br&gt;
&lt;/span&gt;&lt;font color=#008000&gt;// Virtual method call&lt;/font&gt;
&lt;br&gt;
f.foo();&lt;br&gt;
f.foo2();&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;
&lt;br&gt;
&lt;font color=#008000&gt;// Non virtual method calls&lt;/font&gt;
&lt;br&gt;
f.boo();&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Son calls&lt;br&gt;
&lt;/span&gt;&lt;font color=#008000&gt;// Virtual method call&lt;br&gt;
&lt;/font&gt;s.foo();&lt;br&gt;
&lt;br&gt;
&lt;font color=#008000&gt;// Non virtual method calls&lt;br&gt;
&lt;/font&gt;s.boo();&lt;br&gt;
s.moo();&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
what really happens behind ?&lt;br&gt;
lets view a part of the disassembly code&lt;br&gt;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Virtual method call&lt;/span&gt;
&lt;br&gt;
s.foo();&lt;br&gt;
00000065 mov ecx,esi 
&lt;br&gt;
00000067 mov eax,dword ptr [ecx] 
&lt;br&gt;
&lt;strong&gt;00000069 call dword ptr [eax+38h]&lt;/strong&gt; 
&lt;br&gt;
0000006c nop 
&lt;br&gt;
&lt;br&gt;
s.foo2();&lt;br&gt;
0000006d mov ecx,esi 
&lt;br&gt;
0000006f mov eax,dword ptr [ecx] 
&lt;br&gt;
&lt;strong&gt;00000071 call dword ptr [eax+3Ch]&lt;/strong&gt; 
&lt;br&gt;
00000074 nop 
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Non virtual method calls&lt;/span&gt;
&lt;br&gt;
s.boo();&lt;br&gt;
00000075 mov ecx,esi 
&lt;br&gt;
00000077 cmp dword ptr [ecx],ecx 
&lt;br&gt;
&lt;strong&gt;00000079 call FFAB30A0&lt;/strong&gt; 
&lt;br&gt;
0000007e nop 
&lt;br&gt;
&lt;br&gt;
s.moo();&lt;br&gt;
0000007f mov ecx,esi 
&lt;br&gt;
00000081 cmp dword ptr [ecx],ecx 
&lt;br&gt;
&lt;strong&gt;00000083 call FFAB3158&lt;/strong&gt; 
&lt;br&gt;
00000088 nop &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
we can see clearly that the non virtual call has a direct calling to the function
(a hard coded address),&lt;br&gt;
whereas the virtual method calling points to the virtual method table that resides
in the Son object.&lt;br&gt;
lets take a look on that table :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EEClass:
00a21370&lt;br&gt;
Module: 00a22c24&lt;br&gt;
Name: VTF.Son&lt;br&gt;
mdToken: 02000004 (E:\PROJECTS\vtf 2005\VTF\VTF\bin\Debug\VTF.exe)&lt;br&gt;
BaseSize: 0xc&lt;br&gt;
ComponentSize: 0x0&lt;br&gt;
Number of IFaces &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; IFaceMap:
0&lt;br&gt;
Slots &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; VTable:
9&lt;br&gt;
--------------------------------------&lt;br&gt;
MethodDesc Table&lt;br&gt;
Entry&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MethodDesc JIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name&lt;br&gt;
7934cdcc 79137ab8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreJIT System.Object.ToString()&lt;br&gt;
7934bba0 79137ac0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreJIT System.Object.Equals(System.Object)&lt;br&gt;
7934bb90 79137ad8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreJIT System.Object.GetHashCode()&lt;br&gt;
793424c0 79137ae0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PreJIT System.Object.Finalize()&lt;br&gt;
&lt;strong&gt;00a231b8 00a23140&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VTF.Son.foo()&lt;br&gt;
00a23100 00a23088&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VTF.Father.foo2()&lt;/strong&gt;
&lt;br&gt;
00a231c8 00a23148&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NONE&amp;nbsp;&amp;nbsp;&amp;nbsp;VTF.Son.moo()&lt;br&gt;
00a231d8 00a23150&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NONE&amp;nbsp;&amp;nbsp;&amp;nbsp;VTF.Son.faaBase()&lt;br&gt;
00a231e8 00a23158&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VTF.Son..ctor()&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
we can see a couple of things from this table:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
VT lists all the methods the son object holds 
&lt;li&gt;
VT&amp;nbsp;lists the virtual functions of the father that are virtual 
&lt;li&gt;
When the son object overrides one of the virtual methods that the father implements, 
&lt;br&gt;
the father method entry is being replaced by the new son method (line 5 at the table
- Son.foo()) 
&lt;li&gt;
the VT does not list father method that are not virtual.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
actually the Son.moo() method looks a little unnecessary in the VT&amp;nbsp;due to the
fact that the function is not virtual and will be addressed directly and not by the
VT.
&lt;/p&gt;
&lt;p&gt;
in conclusion, think twice before you declare a method as virtual, because it contains
some performance hit
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=83234cdf-66bc-4a38-aad0-b9a1454af394" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,83234cdf-66bc-4a38-aad0-b9a1454af394.aspx</comments>
      <category>.Net</category>
      <category>job interviews</category>
      <category>Under the hood</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=bfcb4c1b-7cbe-4d1c-99a4-1658afa50496</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,bfcb4c1b-7cbe-4d1c-99a4-1658afa50496.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,bfcb4c1b-7cbe-4d1c-99a4-1658afa50496.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=bfcb4c1b-7cbe-4d1c-99a4-1658afa50496</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
ok, this is the point where all the OOP guru's can contribute some of thier knowledge.<br />
i'm facing some strange problem maybe someone can point the solution.
</p>
        <p>
i'm having this code :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Father<br />
{<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Son:Father<br />
{<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Tester<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> TestFunc(Father
a)<br />
    {<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Test()<br />
    {<br />
        Son aSon <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Son();<br /><br />
        TestFunc(aSon);<br />
    }    <br />
}</span>
        </p>
        <p>
this code will compile with no problems.
</p>
        <p>
but if i want to pass the object by reference, it will cause a compilation error.
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Father<br />
{<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Son:Father<br />
{<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Tester<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> TestFunc(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ref</span> Father
a)<br />
    {<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Test()<br />
    {<br />
        Son aSon <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Son();<br /><br />
        TestFunc(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ref</span> aSon);<br />
    }    <br />
}</span>
        </p>
the error i'm getting is something like : "can not convert 'ref son' to 'ref Father'
"<br />
does someone knows why ?<img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=bfcb4c1b-7cbe-4d1c-99a4-1658afa50496" /><br /><hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Lost in Polymorphism world</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,bfcb4c1b-7cbe-4d1c-99a4-1658afa50496.aspx</guid>
      <link>http://www.krokhmal.com/2007/04/16/LostInPolymorphismWorld.aspx</link>
      <pubDate>Mon, 16 Apr 2007 11:12:18 GMT</pubDate>
      <description>&lt;p&gt;
ok, this is the point where all the OOP guru's can contribute some of thier knowledge.&lt;br&gt;
i'm facing some strange problem maybe someone can point the solution.
&lt;/p&gt;
&lt;p&gt;
i'm having this code :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Father&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Son:Father&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Tester&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; TestFunc(Father
a)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Test()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Son aSon &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Son();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TestFunc(aSon);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
this code will compile with no problems.
&lt;/p&gt;
&lt;p&gt;
but if i want to pass the object by reference, it will cause a compilation error.
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Father&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Son:Father&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Tester&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; TestFunc(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ref&lt;/span&gt; Father
a)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Test()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Son aSon &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Son();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TestFunc(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ref&lt;/span&gt; aSon);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
the error i'm getting is something like : "can not convert 'ref son' to 'ref Father'
"&lt;br&gt;
does someone knows why ?&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=bfcb4c1b-7cbe-4d1c-99a4-1658afa50496" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,bfcb4c1b-7cbe-4d1c-99a4-1658afa50496.aspx</comments>
      <category>.Net</category>
      <category>.Net/C#</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=84b017d2-f4b3-4481-8847-221bf47dd26b</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,84b017d2-f4b3-4481-8847-221bf47dd26b.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,84b017d2-f4b3-4481-8847-221bf47dd26b.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=84b017d2-f4b3-4481-8847-221bf47dd26b</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
couple weeks ago, my friend and co-worker, <a href="http://www.human-debugger.net/">shani
raba</a>, presented me a problem.<br />
they have some sealed application as an .exe file that throws some exceptions and
crashes their application.
</p>
        <p>
So, i Thought that is a good idea to wrap the targeted application with reflection,
and catch the unhandled thrown exceptions.
</p>
        <p>
to demonstrate this,<br />
I've created an application with a button that throws an exception.
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> button1_Click(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
System.EventArgs e)<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Exception(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"my
Exception, need to be wrapped"</span>);<br />
}</span>
        </p>
        <p>
the next thing that we need to create is the wrapper.
</p>
        <p>
so, creating a console application with this code should have solved the problem:
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">[STAThread]<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Main(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
args)<br />
{<br /><br />
    Assembly assembly <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Assembly.LoadFrom
(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"cashTester.exe"</span>);<br /><br />
    Type t <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> assembly.GetType(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"cashTester.Form1"</span>);<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> o <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Activator.CreateInstance(t);<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">try</span><br />
    {<br />
        Application.Run((Form)o); 
<br />
    }<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">catch</span>(Exception
ex)<br />
    {<br />
        Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"exception
was thrown : "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ex.Message);<br />
    }<br />
}</span>
        </p>
        <p>
running this code in debug mode successfully catch the exception from the winform.<br />
but, for some reason, in a normal run, this code won't catch the exception.
</p>
        <p>
makes you wonder, huh ?
</p>
        <p>
so i did some thinking, what on earth can make this phenomena ?<br />
The answer is : Threads.<br />
Yes, like it or not, but this is the subject that everyone tries to avoid it.<br />
everyone knows it exists, and no one really likes it,<br />
but we can't run from the problem, we need to confront it.
</p>
        <p>
So, what can we do ?
</p>
        <p>
since <font size="2">Application.Run launches a new thread, </font>we can add to the
Application.ThreadException event handler, an exception handling method.<br /></p>
        <p>
like this class :
</p>
        <p>
 
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
The Wrapper class</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Wrapper<br />
{<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Public cunstructor</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> Wrapper()<br />
    {<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
This function will initialize the exception handling</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Init()<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
define handlers for unhandled exceptions</span><br />
        AppDomain.CurrentDomain.UnhandledException
+= <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> UnhandledExceptionEventHandler(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>.exp);<br />
        Application.ThreadException +=<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> System.Threading.ThreadExceptionEventHandler(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>.ThreadExp);<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
This method is for the threads exceptions</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="o"&gt;the object&lt;/param&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="args"&gt;Thread exception args&lt;/param&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ThreadExp(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> o,
System.Threading.ThreadExceptionEventArgs args)<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Write the message to the console</span><br />
        Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Unhandled
thread exception was thrown : "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> args.Exception.Message);<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
This method is for the unhandled exceptions from the main thread</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="o"&gt;the object&lt;/param&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="args"&gt;exception arguments&lt;/param&gt;</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> exp(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> o,System.UnhandledExceptionEventArgs
args)<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Write the message to the console</span><br />
        Console.Write(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Unhandled
exception was thrown : "</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ((Exception)args.ExceptionObject).Message);<br />
    }<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Run()<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Load the assembly</span><br />
        Assembly assembly <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Assembly.LoadFrom
(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"cashTester.exe"</span>);<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
get the type of the object</span><br />
        Type t <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> assembly.GetType(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"cashTester.Form1"</span>);<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
invoke it</span><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> o <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Activator.CreateInstance(t);<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Run the application - note that this line starts an additional thread</span><br />
        Application.Run((Form)o);<br />
    }<br />
}</span>
        </p>
        <p>
 
</p>
        <p>
now, all we need is to launch it :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
The main entry point for the application.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
            <br />
[STAThread]<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Main(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
args)<br />
{<br />
    Wrapper w <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Wrapper();<br />
    w.Init();<br />
    w.Run();<br />
}</span>
        </p>
        <p>
 
</p>
        <p>
now we got an exception wrapper for launching applications.
</p>
        <p>
          <a href="http://www.human-debugger.net/">Shani</a>, tell me if that helped ...
</p>
        <p>
p.s.<br />
There are more ways to do it, but this is the simplest one
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=84b017d2-f4b3-4481-8847-221bf47dd26b" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Wrapping Unhandled exceptions from a WinForm application</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,84b017d2-f4b3-4481-8847-221bf47dd26b.aspx</guid>
      <link>http://www.krokhmal.com/2007/03/04/WrappingUnhandledExceptionsFromAWinFormApplication.aspx</link>
      <pubDate>Sun, 04 Mar 2007 18:35:22 GMT</pubDate>
      <description>&lt;p&gt;
couple weeks ago, my friend and co-worker, &lt;a href="http://www.human-debugger.net/"&gt;shani
raba&lt;/a&gt;,&amp;nbsp;presented me a problem.&lt;br&gt;
they have some sealed application as an .exe file that throws some exceptions and
crashes their application.
&lt;/p&gt;
&lt;p&gt;
So, i Thought that is a good idea to wrap the targeted application with reflection,
and catch the unhandled thrown exceptions.
&lt;/p&gt;
&lt;p&gt;
to demonstrate this,&lt;br&gt;
I've created an application with a button that throws an exception.
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; button1_Click(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
System.EventArgs e)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;throw&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Exception(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"my
Exception, need to be wrapped"&lt;/span&gt;);&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
the next thing that we need to create is the wrapper.
&lt;/p&gt;
&lt;p&gt;
so, creating a console application with this code should have solved the problem:
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;[STAThread]&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Main(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Assembly assembly &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Assembly.LoadFrom
(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"cashTester.exe"&lt;/span&gt;);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Type t &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; assembly.GetType(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"cashTester.Form1"&lt;/span&gt;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; o &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Activator.CreateInstance(t);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;try&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.Run((Form)o); 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;catch&lt;/span&gt;(Exception
ex)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"exception
was thrown : "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ex.Message);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
running this code in debug mode successfully catch the exception from the winform.&lt;br&gt;
but, for some reason, in a normal run, this code won't catch the exception.
&lt;/p&gt;
&lt;p&gt;
makes you wonder, huh ?
&lt;/p&gt;
&lt;p&gt;
so i did some thinking, what on earth can make this phenomena ?&lt;br&gt;
The answer is : Threads.&lt;br&gt;
Yes, like it or not, but this is the subject that everyone tries to avoid it.&lt;br&gt;
everyone knows it exists, and no one really likes it,&lt;br&gt;
but we can't run from the problem, we need to confront it.
&lt;/p&gt;
&lt;p&gt;
So, what can we do ?
&lt;/p&gt;
&lt;p&gt;
since &lt;font size=2&gt;Application.Run launches a new thread, &lt;/font&gt;we can add to the
Application.ThreadException event handler, an exception handling method.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
like this class :
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
The Wrapper class&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Wrapper&lt;br&gt;
{&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Public cunstructor&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; Wrapper()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
This function will initialize the exception handling&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Init()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
define handlers for unhandled exceptions&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AppDomain.CurrentDomain.UnhandledException
+= &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; UnhandledExceptionEventHandler(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;.exp);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.ThreadException +=&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; System.Threading.ThreadExceptionEventHandler(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;.ThreadExp);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
This method is for the threads exceptions&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="o"&amp;gt;the object&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="args"&amp;gt;Thread exception args&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; ThreadExp(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; o,
System.Threading.ThreadExceptionEventArgs args)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Write the message to the console&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Unhandled
thread exception was thrown : "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; args.Exception.Message);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
This method is for the unhandled exceptions from the main thread&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="o"&amp;gt;the object&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="args"&amp;gt;exception arguments&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; exp(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; o,System.UnhandledExceptionEventArgs
args)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Write the message to the console&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.Write(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Unhandled
exception was thrown : "&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ((Exception)args.ExceptionObject).Message);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Run()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Load the assembly&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Assembly assembly &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Assembly.LoadFrom
(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"cashTester.exe"&lt;/span&gt;);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
get the type of the object&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Type t &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; assembly.GetType(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"cashTester.Form1"&lt;/span&gt;);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
invoke it&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; o &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Activator.CreateInstance(t);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run the application - note that this line starts an additional thread&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.Run((Form)o);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
now, all we need is to launch it :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
The main entry point for the application.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
[STAThread]&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Main(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;[]
args)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Wrapper w &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Wrapper();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;w.Init();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;w.Run();&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
now we got an exception wrapper for launching applications.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.human-debugger.net/"&gt;Shani&lt;/a&gt;, tell me if that helped ...
&lt;/p&gt;
&lt;p&gt;
p.s.&lt;br&gt;
There are more ways to do it, but this is the simplest one
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=84b017d2-f4b3-4481-8847-221bf47dd26b" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,84b017d2-f4b3-4481-8847-221bf47dd26b.aspx</comments>
      <category>.Net</category>
      <category>Architectural solutions</category>
      <category>Threading</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=c3d700fe-310b-4350-96ba-86cdade9d364</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,c3d700fe-310b-4350-96ba-86cdade9d364.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,c3d700fe-310b-4350-96ba-86cdade9d364.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c3d700fe-310b-4350-96ba-86cdade9d364</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday, good friend of mine, Lev rosenblit, asked me a good question.<br />
what are the life cycle of static objects in an aspx page.<br />
so, at first without any hesitation, i answered that the object will die after the
request event ends.<br />
the dude insists that I'm wrong on that matter, so i decided to check it out .
</p>
        <p>
here is some code snippet to check it out :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        private</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> myStaticInt <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 0;<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Page_Load(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
System.EventArgs e)<br />
        {<br />
            myStaticInt++;<br />
            Response.Write(myStaticInt);<br />
        }</span>
        </p>
        <p>
by theory (which is objects in an aspx page die after the end of the request), this
code should print the number "1" on each request.<br />
but the result was different, on each request, the result increased.
</p>
        <p>
digging a little on the web, i found that static objects live inside the App domain
and not in the page context.<br />
This interesting fact raised some interesting question, an architectural one:<br />
what would happen if the code run in NLB configuration (Network Load Balancing)?
</p>
        <p>
on that matter their is a session state issue which is solved by getting the session
state from a shared database,<br />
but what about the static objects that live inside the App domain ? 
<br />
what can be done to share those object ?
</p>
        <p>
from my point of view, this is a bad choice in architecture when you choosing to use
static objects inside your page.<br />
thus, it won't always work, and will be hardware Dependant system.
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=c3d700fe-310b-4350-96ba-86cdade9d364" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Static objects in aspx page - Bad idea</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,c3d700fe-310b-4350-96ba-86cdade9d364.aspx</guid>
      <link>http://www.krokhmal.com/2007/03/04/StaticObjectsInAspxPageBadIdea.aspx</link>
      <pubDate>Sun, 04 Mar 2007 12:17:48 GMT</pubDate>
      <description>&lt;p&gt;
Yesterday, good friend of mine, Lev rosenblit, asked me a good question.&lt;br&gt;
what are the life cycle of static objects in an aspx page.&lt;br&gt;
so, at first without any hesitation, i answered that the object will die after the
request event ends.&lt;br&gt;
the dude insists that I'm wrong on that matter, so i decided to check it out .
&lt;/p&gt;
&lt;p&gt;
here is some code snippet to check it out :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; myStaticInt &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; 0;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Page_Load(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
System.EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;myStaticInt++;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Write(myStaticInt);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
by theory (which is objects in an aspx page die after the end of the request), this
code should print the number "1" on each request.&lt;br&gt;
but the result was different, on each request, the result increased.
&lt;/p&gt;
&lt;p&gt;
digging a little on the web, i found that static objects live inside the App domain
and not in the page context.&lt;br&gt;
This interesting fact raised some interesting question, an architectural one:&lt;br&gt;
what would happen if the code run in NLB configuration (Network Load Balancing)?
&lt;/p&gt;
&lt;p&gt;
on that matter their is a session state issue which is solved by getting the session
state from a shared database,&lt;br&gt;
but what about the static objects that live inside the App domain ? 
&lt;br&gt;
what can be done to share those object ?
&lt;/p&gt;
&lt;p&gt;
from my point of view, this is a bad choice in architecture when you choosing to use
static objects inside your page.&lt;br&gt;
thus, it won't always work, and will be hardware Dependant system.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=c3d700fe-310b-4350-96ba-86cdade9d364" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,c3d700fe-310b-4350-96ba-86cdade9d364.aspx</comments>
      <category>.Net</category>
      <category>Architectural solutions</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=83987760-38c6-4b8a-b611-e0632746e634</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,83987760-38c6-4b8a-b611-e0632746e634.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,83987760-38c6-4b8a-b611-e0632746e634.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=83987760-38c6-4b8a-b611-e0632746e634</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Let me tell you some story thats happening now.<br />
couple month ago i hired some folks to do a part of some project due to time limits
that i have.<br />
now, i know those guys personally and checking thier technical backgroung seemed to
be irrelevant (mistake no' 1).<br />
i thought, how hard can i be to make some GUI to an application that all the other
layers are done (3 tier architecture).
</p>
        <p>
So, instead of 1 month development it turned to more than 3 months already, (30% progress)<br />
god knows how long it will take them to finish it .
</p>
        <p>
and now, when i finally see some progress, i see code like this :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (!Page.IsValid)<br />
{<br />
}<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span><br />
{<br />
    InsertNewCustomer();<br />
    lblClientMessage.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> NewClientText();<br />
    ClearText();<br />
}</span>
        </p>
        <p>
ok, who are does guys ?<br />
you think that a skilled programmer with 3 years of expirience would not write such
crapy code like this (those things just get me mad.)<br />
why they think that i allow such code to go on production ?<br />
not speaking about the XSS holes that they made (just by the book....)<br />
looks like they didn't read <a href="http://www.krokhmal.com/2006/10/20/WritingSecureNetCodeForWebApplicationsLesson1XSSPrevention.aspx">this
guide</a></p>
        <p>
i mean look at this thing, how many mistakes you can do as a single code :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> NewClientText()<br />
        {<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> strNewClient <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtName.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
"</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> txtFamily.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
"</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"הוזן
בהצלחה"</span>;<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> strNewClient;<br />
        }<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> btnAdd_Click(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
System.EventArgs e)<br />
        {<br />
            lblClientMessage.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>;<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (!Page.IsValid)<br />
            {<br />
            }<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span><br />
            {<br />
                InsertNewCustomer();<br />
                lblClientMessage.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> NewClientText();<br />
                ClearText();<br />
            }<br />
        }<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> InsertNewCustomer()<br />
        {<br />
            Customers
newCustomer <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Customers();<br /><br />
            newCustomer.Name <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtName.Text;<br />
            newCustomer.LastName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtFamily.Text;<br />
            newCustomer.Notes <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtNotes.Text;<br />
            newCustomer.isStudent <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> chkStudent.Checked;<br />
            newCustomer.Phone <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> TxtPhone.Text;<br />
            newCustomer.Cellular <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtCellular.Text;<br />
            newCustomer.Email <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtEmail.Text;<br />
            newCustomer.Address <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> txtAddress.Text;<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (txtBirth.Text.Trim()
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>)<br />
            {<br />
                newCustomer.BirthDate <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Convert.ToDateTime(txtBirth.Text);<br />
            }<br /><br />
            custDal.Add(newCustomer);<br />
        }<br /></span>
        </p>
        <ul>
          <li>
writing data to the page without validating it first 
</li>
          <li>
some logical twists - (if page not valid, dont do anything, else do something...),
why on earth ? why ? 
</li>
          <li>
inserting to the database without validating the input (for those who are femilier
with my architecture, validating is a single line "entity.Validate();" 
</li>
          <li>
no exception managment what so ever. 
</li>
          <li>
no code comments 
</li>
          <li>
            <strong>Client side input validations</strong>
          </li>
        </ul>
        <p>
here is some more goodies from the same author :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">lblAddress.Style.Add(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"text-align"</span>,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"right"</span>);</span>
        </p>
        <p>
what happened to CSS files ?<br />
thier are lots of lines like this defining the style for every object.<br />
i dont wanna know what are they planned to do when they need to change the style one
by one .
</p>
        <p>
man, this is a little piece of code, i'm affraid to see whats going on , on the rest
of the code.
</p>
        <p>
this is some lessons that you learn on the hard way....
</p>
        <p>
          <strong>"i will never hire people without checking thier technical background"<br />
"i will never hire people without checking thier technical background"<br />
"i will never hire people without checking thier technical background"<br />
"i will never hire people without checking thier technical background"<br />
"i will never hire people without checking thier technical background"<br />
"i will never hire people without checking thier technical background"</strong>
        </p>
        <p>
i should better get some things to my own hands before it gets to late .<br />
anyone wants a job to create some gui ?<br /></p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=83987760-38c6-4b8a-b611-e0632746e634" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Hasty hiring makes the project go very long.</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,83987760-38c6-4b8a-b611-e0632746e634.aspx</guid>
      <link>http://www.krokhmal.com/2007/03/02/HastyHiringMakesTheProjectGoVeryLong.aspx</link>
      <pubDate>Fri, 02 Mar 2007 23:02:59 GMT</pubDate>
      <description>&lt;p&gt;
Let me tell you some story thats happening now.&lt;br&gt;
couple month ago i hired some folks to do a part of some project due to time limits
that i have.&lt;br&gt;
now, i know those guys personally and checking thier technical backgroung seemed to
be irrelevant (mistake no' 1).&lt;br&gt;
i thought, how hard can i be to make some GUI to an application that all the other
layers are done (3 tier architecture).
&lt;/p&gt;
&lt;p&gt;
So, instead of 1 month development it turned to more than 3 months already, (30% progress)&lt;br&gt;
god knows how long it will take them to finish it .
&lt;/p&gt;
&lt;p&gt;
and now, when i finally see some progress, i see code like this :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (!Page.IsValid)&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt;
&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InsertNewCustomer();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblClientMessage.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; NewClientText();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClearText();&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
ok, who are does guys ?&lt;br&gt;
you think that a skilled programmer with 3 years of expirience would not write such
crapy code like this (those things just get me mad.)&lt;br&gt;
why they think that i allow such code to go on production ?&lt;br&gt;
not speaking about the XSS holes that they made (just by the book....)&lt;br&gt;
looks like they didn't read &lt;a href="http://www.krokhmal.com/2006/10/20/WritingSecureNetCodeForWebApplicationsLesson1XSSPrevention.aspx"&gt;this
guide&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
i mean look at this thing, how many mistakes you can do as a single code :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; NewClientText()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; strNewClient &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtName.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"
"&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; txtFamily.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"
"&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"הוזן
בהצלחה"&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; strNewClient;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; btnAdd_Click(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
System.EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblClientMessage.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (!Page.IsValid)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InsertNewCustomer();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblClientMessage.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; NewClientText();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClearText();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; InsertNewCustomer()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Customers
newCustomer &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Customers();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.Name &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtName.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.LastName &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtFamily.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.Notes &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtNotes.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.isStudent &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; chkStudent.Checked;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.Phone &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; TxtPhone.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.Cellular &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtCellular.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.Email &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtEmail.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.Address &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; txtAddress.Text;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (txtBirth.Text.Trim()
!&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomer.BirthDate &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Convert.ToDateTime(txtBirth.Text);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;custDal.Add(newCustomer);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
writing data to the page without validating it first 
&lt;li&gt;
some logical twists - (if page not valid, dont do anything, else do something...),
why on earth ? why ? 
&lt;li&gt;
inserting to the database without validating the input (for those who are femilier
with my architecture, validating is a single line "entity.Validate();" 
&lt;li&gt;
no exception managment what so ever. 
&lt;li&gt;
no code comments 
&lt;li&gt;
&lt;strong&gt;Client side input validations&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
here is some more goodies from the same author :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;lblAddress.Style.Add(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"text-align"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"right"&lt;/span&gt;);&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
what happened to CSS files ?&lt;br&gt;
thier are lots of lines like this defining the style for every object.&lt;br&gt;
i dont wanna know what are they planned to do when they need to change the style one
by one .
&lt;/p&gt;
&lt;p&gt;
man, this is a little piece of code, i'm affraid to see whats going on , on the rest
of the code.
&lt;/p&gt;
&lt;p&gt;
this is some lessons that you learn on the hard way....
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;"i will never hire people without checking thier technical background"&lt;br&gt;
"i will never hire people without checking thier technical background"&lt;br&gt;
"i will never hire people without checking thier technical background"&lt;br&gt;
"i will never hire people without checking thier technical background"&lt;br&gt;
"i will never hire people without checking thier technical background"&lt;br&gt;
"i will never hire people without checking thier technical background"&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
i should better get some things to my own hands before it gets to late .&lt;br&gt;
anyone wants a job to create some gui ?&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=83987760-38c6-4b8a-b611-e0632746e634" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,83987760-38c6-4b8a-b611-e0632746e634.aspx</comments>
      <category>.Net</category>
      <category>Life</category>
      <category>XSS</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=16b22ae9-7971-4b75-ac7a-78d5e25b27f2</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,16b22ae9-7971-4b75-ac7a-78d5e25b27f2.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,16b22ae9-7971-4b75-ac7a-78d5e25b27f2.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=16b22ae9-7971-4b75-ac7a-78d5e25b27f2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Well,<br />
after months I'm talking about it and couple of sleepless nights to prepare it, here
it is.
</p>
        <p>
So, what do have here ?
</p>
        <p>
1 powerPoint presentation that explains what is Session Hijacking and XSS.<br />
1 XSS demo.<br />
0 Session hijacking Demo .... (why you ask ? - I'm planning to do another lecture
on the topic for some those who missed it yesterday...)<br />
0 Code included. (like the demos ....will be uploaded some time soon....)
</p>
        <p>
long story short :<br />
this presentation talks about the threats in Session hijacking.<br />
and how to prevent it. - while its not a 100% solution, it certainly raises the bar
for hackers to succeed in the session hijacking attack.
</p>
        <p>
some wise man said to me once,<br />
"for every defense that ever made, someone thought how to break it,<br />
 the only thing we can do, is to narrow down the amount of people that is capable
to perform it."
</p>
        <p>
enjoy.
</p>
        <p>
comments are welcomed :)
</p>
        <p>
          <a href="http://www.krokhmal.com/content/binary/Security.pps">Security.pps (324 KB)</a>
        </p>
        <p>
 
</p>
        <object width="800" height="600">
          <param name="movie" value="http://www.youtube.com/v/TMPnyyrPryc" />
          <embed src="http://www.youtube.com/v/TMPnyyrPryc" type="application/x-shockwave-flash" width="800" height="600">
          </embed>
        </object>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=16b22ae9-7971-4b75-ac7a-78d5e25b27f2" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Session hijacking  - prevention oriented</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,16b22ae9-7971-4b75-ac7a-78d5e25b27f2.aspx</guid>
      <link>http://www.krokhmal.com/2007/03/02/SessionHijackingPreventionOriented.aspx</link>
      <pubDate>Fri, 02 Mar 2007 13:32:40 GMT</pubDate>
      <description>&lt;p&gt;
Well,&lt;br&gt;
after months I'm talking about it and couple of sleepless nights to prepare it, here
it is.
&lt;/p&gt;
&lt;p&gt;
So, what do have here ?
&lt;/p&gt;
&lt;p&gt;
1 powerPoint presentation that explains what is Session Hijacking and XSS.&lt;br&gt;
1 XSS demo.&lt;br&gt;
0 Session hijacking Demo .... (why you ask ? - I'm planning to do another lecture
on the topic for some those who missed it yesterday...)&lt;br&gt;
0 Code included. (like the demos ....will be uploaded some time soon....)
&lt;/p&gt;
&lt;p&gt;
long story short :&lt;br&gt;
this presentation talks about the threats in Session hijacking.&lt;br&gt;
and how to prevent it. - while its not a 100% solution, it certainly raises the bar
for hackers to succeed in the session hijacking attack.
&lt;/p&gt;
&lt;p&gt;
some wise man said to me once,&lt;br&gt;
"for every defense that ever made, someone thought how to break it,&lt;br&gt;
&amp;nbsp;the only thing we can do, is to narrow down the amount of people that is capable
to perform it."
&lt;/p&gt;
&lt;p&gt;
enjoy.
&lt;/p&gt;
&lt;p&gt;
comments are welcomed :)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.krokhmal.com/content/binary/Security.pps"&gt;Security.pps (324 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;object width="800" height="600"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/TMPnyyrPryc"&gt;&gt;&lt;embed src="http://www.youtube.com/v/TMPnyyrPryc" type="application/x-shockwave-flash" width="800" height="600"&gt;&lt;/embed&gt;
&lt;/object&gt;&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=16b22ae9-7971-4b75-ac7a-78d5e25b27f2" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,16b22ae9-7971-4b75-ac7a-78d5e25b27f2.aspx</comments>
      <category>.Net</category>
      <category>Architectural solutions</category>
      <category>Lessons</category>
      <category>Security</category>
      <category>XSS</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=d11276b4-9a11-4dd6-b40f-4d1f8564fe4a</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,d11276b4-9a11-4dd6-b40f-4d1f8564fe4a.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,d11276b4-9a11-4dd6-b40f-4d1f8564fe4a.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d11276b4-9a11-4dd6-b40f-4d1f8564fe4a</wfw:commentRss>
      <title>Writing secure .Net code for web applications - Lesson 1  - XSS prevention</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,d11276b4-9a11-4dd6-b40f-4d1f8564fe4a.aspx</guid>
      <link>http://www.krokhmal.com/2006/10/20/WritingSecureNetCodeForWebApplicationsLesson1XSSPrevention.aspx</link>
      <pubDate>Fri, 20 Oct 2006 12:37:47 GMT</pubDate>
      <description>&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;Security is one
of the most important subjects when creating some business (not necessary a web business
or even computer related).&lt;br&gt;
think about investing lot of time developing your business, and then seeing it all&amp;nbsp;ripped
apart, just because a sensitive information was reviled to some unwanted individuals,
or even worse, gone global to the public.&lt;br&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
Of course, security in not only related to stealing data, messing with the business
reputation can be devastating just as much as the mentioned above.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;When developing
Web applications, security is highly important due to the reason that the application
is running in the most hostile environment, I mean, everybody can access it, meaning
that everyone is a potential threat to the system.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;&lt;a href="http://en.wikipedia.org/wiki/XSS"&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;Cross
Site Scripting&lt;/span&gt;&lt;/a&gt; (AKA XSS) is one of the known and ancient methods to exploit
security holes on the web.&lt;br&gt;
The idea of the method is injecting client side script code to a web application,
which will perform an additional task at the client side.&lt;br&gt;
It may seem to some as a harmless thing, but actually, it can trigger much dangerous
attacks such as session hijacking, one-click attacks and&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Phishing"&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;Phishing.&lt;/span&gt;&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
Well, this post actually not about how to conduct an XSS attack, but how to avoid
being an XSS victim.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;&amp;nbsp;So, what do
you have to do in order to prevent XSS? &lt;/span&gt;&lt;span style="COLOR: black"&gt;&lt;font size=3&gt;&lt;font face="Times New Roman"&gt;- &lt;b&gt;INPUT
VALIDATION.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="COLOR: #003300"&gt;
&lt;o:p&gt;
&lt;font face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;&amp;nbsp;Let's take
a look what does the .Net framework has to offer on this matter 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;font color=#000000&gt;ValidateRequest
– page directive&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt; 
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;font color=#000000&gt;Built-in .Net
validation controls (such as "required field validator", "Range Validator&lt;span style="COLOR: black"&gt;",
and so…)&lt;/span&gt;&lt;/font&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt; 
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Server Side validation.&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;&lt;a href="http://www.asp.net/faq/RequestValidation.aspx"&gt;ValidateRequest&lt;/a&gt; directive
– &lt;b&gt;Enabled&lt;/b&gt; by default, supposed to "protect" All the input to the page from
XSS.&lt;br&gt;
It looks for "&amp;lt;" and "&amp;gt;" tags, probably by some regulars expressions, the problem
with this option is that it limits &lt;b&gt;ALL &lt;/b&gt;inputs, even the intended ones (such
as XML, HTML tags and so…).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;a href="http://www.w3schools.com/aspnet/aspnet_refvalidationcontrols.asp"&gt;Built-in
.Net validation controls&lt;/a&gt;&lt;span style="COLOR: black"&gt; – The framework provides probably
all the input validation that you will need when writing it.&lt;br&gt;
Starting from required fields, numerics values, Regular expressions, and even write
your own custom validation.&lt;br&gt;
The problem with it, that it gives the developer a feeling that once the validation
is made, it can't be tempered by the client, which &lt;b&gt;IS NOT TRUE.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Note that the common
use of these tools is on the &lt;b&gt;client side&lt;/b&gt;, which makes the whole validation
process irrelevant.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Ask yourself as
a developer if you setting the "EnableClientScript" property on the validation control
when you use it? – The common answer will be yes, because it improves performance
by saving round trips to the server.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;But if the question
would be, have you did some extra coding to ensure server side validation to occur?
– Unfortunately, the common answer will be &lt;b&gt;NO&lt;/b&gt;.&lt;b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Note to yourself
– &lt;b&gt;This is no' 1 reason for XSS vulnerabilities in ASP.NET applications.&lt;/b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Server Side validation
– This is where your coding skills starts to kick in.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;This is where you
need to stop, and start thinking about security for your application.&lt;br&gt;
A rooky developer will probably go straight to developing a page , neglecting the
security aspect, while the more experienced developer will design a total solution,
considering many aspects of the application, security would be one of the top issues
(if not the first).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt;Lets see some examples
:&lt;br&gt;
&lt;br&gt;
Lets create this asp.net page :&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana"&gt; 
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;%@
Page language=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"c#"&lt;/span&gt; validateRequest=&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;false&lt;/span&gt; Codebehind=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"WebForm1.aspx.cs"&lt;/span&gt; AutoEventWireup=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"false"&lt;/span&gt; Inherits=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"SecurityExample.WebForm1"&lt;/span&gt; enableViewStateMac=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"True"&lt;/span&gt;%&amp;gt;&lt;br&gt;
&amp;lt;!DOCTYPE HTML PUBLIC &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"-//W3C//DTD
HTML 4.0 Transitional//EN"&lt;/span&gt; &amp;gt;&lt;br&gt;
&amp;lt;HTML&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;HEAD&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;WebForm1&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta content=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Microsoft
Visual Studio .NET 7.1"&lt;/span&gt; name=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"GENERATOR"&lt;/span&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta content=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"C#"&lt;/span&gt; name=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"CODE_LANGUAGE"&lt;/span&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta content=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"JavaScript"&lt;/span&gt; name=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"vs_defaultClientScript"&lt;/span&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta content=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"http://schemas.microsoft.com/intellisense/ie5"&lt;/span&gt; name=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"vs_targetSchema"&lt;/span&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/HEAD&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;body MS_POSITIONING=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"GridLayout"&lt;/span&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;form id=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Form1"&lt;/span&gt; method=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"post"&lt;/span&gt; runat=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"server"&lt;/span&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:textbox
id=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"TextBox1"&lt;/span&gt; style=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Z-INDEX:
101; LEFT: 96px; POSITION: absolute; TOP: 48px"&lt;/span&gt; runat=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"server"&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MaxLength=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"5"&lt;/span&gt; Width=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"160px"&lt;/span&gt;&amp;gt;&amp;lt;/asp:textbox&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:regularexpressionvalidator
id=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"RegularExpressionValidator1"&lt;/span&gt; style=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Z-INDEX:
102; LEFT: 320px; POSITION: absolute; TOP: 56px"&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;runat=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"server"&lt;/span&gt; Width=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"144px"&lt;/span&gt; ValidationExpression=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"\d{5}"&lt;/span&gt; ControlToValidate=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"TextBox1"&lt;/span&gt; Height=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"40px"&lt;/span&gt; ErrorMessage=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Numbers
with 5 digits only"&lt;/span&gt;&amp;gt;&amp;lt;/asp:regularexpressionvalidator&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:button
id=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Button1"&lt;/span&gt; style=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Z-INDEX:
103; LEFT: 128px; POSITION: absolute; TOP: 144px"&lt;/span&gt; runat=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"server"&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Width=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"112px"&lt;/span&gt; Text=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"send
data"&lt;/span&gt;&amp;gt;&amp;lt;/asp:button&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:label
id=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"lblOutput"&lt;/span&gt; style=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Z-INDEX:
104; LEFT: 112px; POSITION: absolute; TOP: 192px"&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;runat=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"server"&lt;/span&gt; Width=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"136px"&lt;/span&gt; Height=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"16px"&lt;/span&gt; EnableViewState=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"False"&lt;/span&gt;&amp;gt;&amp;lt;/asp:label&amp;gt;&amp;lt;/form&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/HTML&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
lets add some PageLoad code behind :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Page_Load(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
System.EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Check if the current run is postback&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (IsPostBack)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblOutput.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"this
is a postback&amp;lt;br&amp;gt;"&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Activate the page validation&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Page.Validate();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Check if the page is valid&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (Page.IsValid) 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblOutput.Text
+= &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Page
is Valid!"&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblOutput.Text
+= &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Page
NOT valid"&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblOutput.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"this
is NOT a postback&amp;lt;br&amp;gt;"&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Lets look at the code in the page_load method:&lt;br&gt;
Q : I'm calling here to the page validation manually, Why ?&lt;br&gt;
A : The complete process is combined with the following operations :
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Client side validation 
&lt;li&gt;
Postback to the server 
&lt;li&gt;
Page Initialization 
&lt;li&gt;
Page_Load method invoked 
&lt;li&gt;
Desired action&amp;nbsp;invokes the attached method to it (button_click) 
&lt;li&gt;
when the associated control of the action has a causesValidation property set to true,
the action invokes the Page.Validate() 
&lt;br&gt;
method which check the validation of the page, and sets the Page.IsValid property
to true or false if the validation succeeded or not respectively 
&lt;li&gt;
Logic associated with the action of the control is being executed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Suppose the user has managed to cconduct some validation tempering on the client side
(this is really not a hard task to acomplish),&lt;br&gt;
and posted the data manually as a postback.&lt;br&gt;
The server gets the posted data and addresses it as a postback from the page, and
it begins to proccess the data, invokes the Page_Load (with absolute no indication
if the data is valid or not), &lt;strong&gt;executes the Page_load&lt;/strong&gt; method completly
invokes the given operation(say button_click) and executes it completely.&lt;br&gt;
This way if we wont comit Page.Validate() and then check the Page.IsValid method ,
we are risking here with an XSS vulnurability.
&lt;/p&gt;
&lt;p&gt;
Q : So, what is the best way to conduct a server validation ?&lt;br&gt;
A : First, create those validators as you always do.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Then apply this code on your page (or your master page) :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Page.Validate();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(!Page.IsValid)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;throw&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Exception(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Security
Exception occured"&lt;/span&gt;);&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
you can do some other handling besides throwing an exception, like logging, tracing,
a nice message to the user and so on.&lt;br&gt;
Note that this actions will protect you at the Presentation layer but not further
( at the DAL - sql injection , or the&amp;nbsp;Session layer&amp;nbsp;- Session hijacking
and more....)
&lt;/p&gt;
&lt;p&gt;
Here are 10 base guidelines to prevent being an XSS victim :
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Never write to page unfiltered data.(or encoded) 
&lt;li&gt;
Never write to the page straight from the user input. 
&lt;li&gt;
Before handling input, Validate that it is really what you are expecting for. 
&lt;li&gt;
Don't expose exceptions to the client. 
&lt;li&gt;
Don't expose Any internal information about the application to the client. 
&lt;li&gt;
Never rely on client side validations. 
&lt;li&gt;
Know the existing threats and vulnerabilities. 
&lt;li&gt;
Don't use built-in features if you're not completely understand what they are doing. 
&lt;li&gt;
Try to think "out of the box" in security related issues 
&lt;li&gt;
&lt;strong&gt;Handle security issue by design, not by mistake.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/span&gt;&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=d11276b4-9a11-4dd6-b40f-4d1f8564fe4a" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,d11276b4-9a11-4dd6-b40f-4d1f8564fe4a.aspx</comments>
      <category>.Net</category>
      <category>Lessons</category>
      <category>Security</category>
      <category>XSS</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=5122c2fc-233d-4f82-9fab-3c7739efbc88</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,5122c2fc-233d-4f82-9fab-3c7739efbc88.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,5122c2fc-233d-4f82-9fab-3c7739efbc88.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5122c2fc-233d-4f82-9fab-3c7739efbc88</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
an Interesting article I've read about the next .net framework,<br />
apparently the new framework wont contain such drastic changes like .Net 1.1 VS 2.0
at the CLR or at the language features,<br />
but, instead it will bring some architectural solutions for different tasks such as
distributed programming, authentication, presentation and probably many more.
</p>
        <p>
check out <a href="http://www.informit.com/articles/article.asp?p=659520&amp;seqNum=1&amp;rl=1">this
article </a>about the issue
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=5122c2fc-233d-4f82-9fab-3c7739efbc88" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>.Net 3.0 - an architectural update for the .Net framework</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,5122c2fc-233d-4f82-9fab-3c7739efbc88.aspx</guid>
      <link>http://www.krokhmal.com/2006/10/16/Net30AnArchitecturalUpdateForTheNetFramework.aspx</link>
      <pubDate>Mon, 16 Oct 2006 20:42:27 GMT</pubDate>
      <description>&lt;p&gt;
an Interesting article I've read about the next .net framework,&lt;br&gt;
apparently the new framework wont contain such drastic changes like .Net 1.1 VS 2.0
at the CLR or at the language features,&lt;br&gt;
but, instead it will bring some architectural solutions for different tasks such as
distributed programming, authentication, presentation and probably many more.
&lt;/p&gt;
&lt;p&gt;
check out &lt;a href="http://www.informit.com/articles/article.asp?p=659520&amp;amp;seqNum=1&amp;amp;rl=1"&gt;this
article &lt;/a&gt;about the issue
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=5122c2fc-233d-4f82-9fab-3c7739efbc88" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,5122c2fc-233d-4f82-9fab-3c7739efbc88.aspx</comments>
      <category>.Net</category>
      <category>Architectural solutions</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=f82f3f4b-d7bf-4f16-b31a-7ab08585e16c</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,f82f3f4b-d7bf-4f16-b31a-7ab08585e16c.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,f82f3f4b-d7bf-4f16-b31a-7ab08585e16c.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f82f3f4b-d7bf-4f16-b31a-7ab08585e16c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As you know, Microsoft didn't intended that you access the SPS database, but via object
model <strong>only</strong>.<br />
the problem that it has many bugs, performance issues, security issues and lots lots
problems that will make the programmer's life a living hell.<br /><br />
So, lets see how can we break the 1st guideline of SPS programming - "<strong>do not
use the SPS database directly"</strong>.<br />
man , I'm feeling like a criminal now, presenting a guide how to do something that
Microsoft invested a lot of effort to prevent us from doing.
</p>
        <p>
Lets get down to business,<br />
don't count that the connection string is laying in some property, this one we need
to do some dirty work.
</p>
        <p>
A little background how we are going to do it:
</p>
        <p>
The connection string looks like this :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Integrated
Security=SSPI;Server=someServer;database=SomeDatabase"</span>
          </span>
        </p>
        <p>
as you can see, the only thing that can change here is the server name and the database
name.<br /><br />
lets create a core function that will receive DB collection and the desired site
guid and construct the connection string.
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> GetConnectionStringForSite(SPContentDatabaseCollection
DBs, Guid siteGuid)<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> rc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>;<br />
    SPContentDatabase oDB <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i=0;
i&lt;DBs.Count;i++)<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Get the database</span><br />
        oDB <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> DBs[i];<br /><br />
        SqlCommand c <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SqlCommand();<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> strConn <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Integrated
Security=SSPI;Server="</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> oDB.Server <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">";database="</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> oDB.Name;<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span>(SqlConnection
conn <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SqlConnection(strConn))<br />
        {<br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Set the Connection</span><br />
            c.Connection <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> conn;<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">try</span><br />
            {<br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Open the connection</span><br />
                conn.Open();<br /><br />
                c.CommandText <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"SELECT
FullUrl FROM Sites where Id=@Id"</span>;<br /><br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Set the parameter</span><br />
                c.Parameters.Add(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SqlParameter(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"@Id"</span>,System.Data.SqlDbType.UniqueIdentifier));<br />
                c.Parameters[<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"@Id"</span>].Value <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> siteGuid;<br /><br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Execute reader</span><br />
                SqlDataReader
reader <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> c.ExecuteReader(System.Data.CommandBehavior.SingleRow);<br /><br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
check if we have rows</span><br />
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> hasRows <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> reader.HasRows;<br /><br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Close the connection and the reader</span><br />
                reader.Close();<br />
                conn.Close();<br /><br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Check if it got rows</span><br />
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(hasRows)<br />
                {<br />
                    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Set the return value</span><br />
                    rs <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> strConn;<br /><br />
                    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Stop iterating through the DB's</span><br />
                    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">break</span>;<br />
                }<br /><br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Close the reader</span><br />
                reader.Close();<br />
            }<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">finally</span><br />
            {<br />
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Close the connection</span><br />
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(conn.State
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> System.Data.ConnectionState.Closed)
conn.Close();<br />
                oDB <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br />
            }<br />
        }<br />
    }<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> rc;<br />
}</span>
        </p>
        <p>
 
</p>
        <p>
this function will be placed in a dedicated class, i call is "SPSDB"
</p>
        <p>
lets create the class itself and its private members
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> SPSDB<br />
    {<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> _conString <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>;<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> _vsUrl <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">""</span>;<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> String
URL<br />
        {<br />
            get{<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> _vsURL;}<br />
        }<br />
    }</span>
        </p>
        <p>
now we need to write the constructor and the connection "factory"
</p>
        <p>
the constructor will look like this :<br /></p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> SPSDB(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> siteUrl)<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span>(Microsoft.SharePoint.Administration.SPGlobalAdmin
ga <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Microsoft.SharePoint.Administration.SPGlobalAdmin())<br />
    {<br />
        Microsoft.SharePoint.Administration.SPVirtualServerCollection
VSc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> ga.VirtualServers;<br /><br />
        SPVirtualServer vs <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br />
        Guid g;<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> isFound <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">false</span>;<br />
        <br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Run through all the VS collection</span><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i=0;
i&lt;VSc.Count;i++)<br />
        {<br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Get the virtual server reference</span><br />
            vs <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> VSc[i];<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
if the current vs is not from the needed state than continue to the next VS</span><br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(vs.state
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> SPVirtualServerState.Ready)<br />
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">continue</span>;<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Run through all the sites in the vs</span><br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> j=0;
j&lt; vs.Sites.Count;j++)<br />
            {<br />
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span>(SPSite
s <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> vs.Sites[j])<br />
                {<br />
                    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Check if we found the needed vs</span><br />
                    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(s.Url.ToLower()
== siteUrl.ToLower())<br />
                    {<br />
                        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Save the needed data</span><br />
                        isFound <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>;<br />
                        g <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> s.ID;<br />
                        _vsURL <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> vs.Url.ToString();<br />
                        _conString <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> GetConnectionStringForSite(vs.ContentDatabases,g);<br />
                        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">break</span>;<br />
                    }<br />
                }<br />
            }<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Check if the vs has been found</span><br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(curVs
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">break</span>;<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Clear the virtual server object</span><br />
            vs <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Clear memory</span><br />
            GC.Collect();<br />
            GC.WaitForPendingFinalizers();<br />
        }<br /><br />
        <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Throw an exception if the site guid is not there</span><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(!isFound)<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Exception(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"the
given site url cannot be found"</span>);<br />
        <br />
    }<br />
}</span>
        </p>
        <p>
and the factory method will look like this :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> SqlConnection
GetCon()<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SqlConnection(_conString);<br />
}</span>
        </p>
        <p>
thats it!<br />
now to use it you can do it like this :<br /></p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SPSDB
dbstuff <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SPSDB(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://www.krokhmal.com"</span>);<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span>(SqlConnection
con <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> dbstuff.GetCon())<br />
{<br />
    <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Your DB code here ...</span><br />
}</span>
        </p>
        <p>
I've added a file attachment to this post with the mentioned class.<br />
enjoy.
</p>
        <a href="http://www.krokhmal.com/content/binary/SPSDB.rar">SPSDB.rar (1.34 KB)</a>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=f82f3f4b-d7bf-4f16-b31a-7ab08585e16c" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Obtaining the connection string for a site in sps - Complete Guide</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,f82f3f4b-d7bf-4f16-b31a-7ab08585e16c.aspx</guid>
      <link>http://www.krokhmal.com/2006/10/11/ObtainingTheConnectionStringForASiteInSpsCompleteGuide.aspx</link>
      <pubDate>Wed, 11 Oct 2006 17:45:58 GMT</pubDate>
      <description>&lt;p&gt;
As you know, Microsoft didn't intended that you access the SPS database, but via object
model &lt;strong&gt;only&lt;/strong&gt;.&lt;br&gt;
the problem that it has many bugs, performance issues, security issues and lots lots
problems that will make the programmer's life a living hell.&lt;br&gt;
&lt;br&gt;
So, lets see how can we break the 1st guideline of SPS programming - "&lt;strong&gt;do not
use the SPS database directly"&lt;/strong&gt;.&lt;br&gt;
man , I'm feeling like a criminal now, presenting a guide how to do something that
Microsoft invested a lot of effort to prevent us from doing.
&lt;/p&gt;
&lt;p&gt;
Lets get down to business,&lt;br&gt;
don't count that the connection string is laying in some property, this one we need
to do some dirty work.
&lt;/p&gt;
&lt;p&gt;
A little background how we are going to do it:
&lt;/p&gt;
&lt;p&gt;
The connection string looks like this :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Integrated
Security=SSPI;Server=someServer;database=SomeDatabase"&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
as you can see, the only thing that can change here is the server name and the database
name.&lt;br&gt;
&lt;br&gt;
lets create a core function that will&amp;nbsp;receive DB collection and the desired site
guid and construct the connection string.
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; GetConnectionStringForSite(SPContentDatabaseCollection
DBs, Guid siteGuid)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; rc &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPContentDatabase oDB &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt;DBs.Count;i++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Get the database&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;oDB &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; DBs[i];&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SqlCommand c &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SqlCommand();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; strConn &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Integrated
Security=SSPI;Server="&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; oDB.Server &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;";database="&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; oDB.Name;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt;(SqlConnection
conn &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SqlConnection(strConn))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Set the Connection&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c.Connection &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; conn;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;try&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Open the connection&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Open();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c.CommandText &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"SELECT
FullUrl FROM Sites where Id=@Id"&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Set the parameter&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c.Parameters.Add(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SqlParameter(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"@Id"&lt;/span&gt;,System.Data.SqlDbType.UniqueIdentifier));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c.Parameters[&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"@Id"&lt;/span&gt;].Value &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; siteGuid;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Execute reader&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SqlDataReader
reader &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; c.ExecuteReader(System.Data.CommandBehavior.SingleRow);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
check if we have rows&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; hasRows &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; reader.HasRows;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Close the connection and the reader&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Close();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Close();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Check if it got rows&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(hasRows)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Set the return value&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; strConn;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Stop iterating through the DB's&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;break&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Close the reader&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reader.Close();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;finally&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Close the connection&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(conn.State
!&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; System.Data.ConnectionState.Closed)
conn.Close();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;oDB &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; rc;&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
this function will be placed in a dedicated class, i call is "SPSDB"
&lt;/p&gt;
&lt;p&gt;
lets create the class itself and its private members
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; SPSDB&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; _conString &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; _vsUrl &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;""&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; String
URL&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;get{&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; _vsURL;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
now we need to write the constructor and the connection "factory"
&lt;/p&gt;
&lt;p&gt;
the constructor will look like this :&lt;br&gt;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; SPSDB(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; siteUrl)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt;(Microsoft.SharePoint.Administration.SPGlobalAdmin
ga &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Microsoft.SharePoint.Administration.SPGlobalAdmin())&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Microsoft.SharePoint.Administration.SPVirtualServerCollection
VSc &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; ga.VirtualServers;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPVirtualServer vs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Guid g;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; isFound &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;false&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through all the VS collection&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt;VSc.Count;i++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Get the virtual server reference&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; VSc[i];&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
if the current vs is not from the needed state than continue to the next VS&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(vs.state
!&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; SPVirtualServerState.Ready)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;continue&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through all the sites in the vs&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; j=0;
j&amp;lt; vs.Sites.Count;j++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt;(SPSite
s &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; vs.Sites[j])&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Check if we found the needed vs&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(s.Url.ToLower()
== siteUrl.ToLower())&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Save the needed data&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isFound &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;g &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; s.ID;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_vsURL &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; vs.Url.ToString();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_conString &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; GetConnectionStringForSite(vs.ContentDatabases,g);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;break&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Check if the vs has been found&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(curVs
!&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;break&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Clear the virtual server object&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Clear memory&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GC.Collect();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GC.WaitForPendingFinalizers();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Throw an exception if the site guid is not there&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(!isFound)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;throw&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Exception(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"the
given site url cannot be found"&lt;/span&gt;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
and the factory method will look like this :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; SqlConnection
GetCon()&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SqlConnection(_conString);&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
thats it!&lt;br&gt;
now to use it you can do it like this :&lt;br&gt;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SPSDB
dbstuff &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SPSDB(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"http://www.krokhmal.com"&lt;/span&gt;);&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt;(SqlConnection
con &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; dbstuff.GetCon())&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Your DB code here ...&lt;/span&gt;
&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
I've added a file attachment to this post with the mentioned class.&lt;br&gt;
enjoy.
&lt;/p&gt;
&lt;a href="http://www.krokhmal.com/content/binary/SPSDB.rar"&gt;SPSDB.rar (1.34 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=f82f3f4b-d7bf-4f16-b31a-7ab08585e16c" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,f82f3f4b-d7bf-4f16-b31a-7ab08585e16c.aspx</comments>
      <category> Sql Server </category>
      <category>.Net</category>
      <category>Lessons</category>
      <category>Microsoft/SPS (sharepoint server)</category>
      <category>Performance</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=7aac8381-fee7-41b8-96a0-fe2dfbf589e2</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,7aac8381-fee7-41b8-96a0-fe2dfbf589e2.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,7aac8381-fee7-41b8-96a0-fe2dfbf589e2.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7aac8381-fee7-41b8-96a0-fe2dfbf589e2</wfw:commentRss>
      <title>Memory leaks using SPS object model.</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,7aac8381-fee7-41b8-96a0-fe2dfbf589e2.aspx</guid>
      <link>http://www.krokhmal.com/2006/10/05/MemoryLeaksUsingSPSObjectModel.aspx</link>
      <pubDate>Thu, 05 Oct 2006 17:53:17 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;Recently i have
given a task to build a tool for managing file versions in share point.&lt;br&gt;
for some architectural decisions and performance issues, I've decided to do the aggregations
directly through the share-point database (yes, even if is &lt;a href="http://www.krokhmal.com/DoesFollowingMicrosoftGuidelinesorAnyGuidelinesIsAlwaysAGoodIdea.aspx"&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;against
Microsoft's guidelines&lt;/span&gt;&lt;/a&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;Considering the
fact that Microsoft invested a lot of afford so you wont find where each SPsite is
located (on which DB) , one of the things i had to do is to iterate through all the
sites in SPsitecollections in every SPVirtualServer in the SPVirtualServerCollection.&lt;br&gt;
Sounds like a lot of "fun".&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;Well, actually
there was problem.&lt;br&gt;
I'll show some bad practices to iterate through that and explain each one&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;
Option 1 :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SPGlobalAdmin
globalAdmin &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SPGlobalAdmin(); 
&lt;br&gt;
SPVirtualServerCollection vServers &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; globalAdmin.VirtualServers; 
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through the virtual servers&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;foreach&lt;/span&gt; (SPVirtualServer
vs &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; vServers) 
&lt;br&gt;
{&amp;nbsp;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
Run through the sites&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&lt;/span&gt; (SPSite
site &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; vs.Sites)&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&lt;/span&gt;(site.Url
== predefinedUrl)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
Do some logic ...&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Option 2 :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SPGlobalAdmin
globalAdmin &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SPGlobalAdmin(); 
&lt;br&gt;
SPVirtualServerCollection vServers &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; globalAdmin.VirtualServers; 
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through the virtual servers&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt;vServers.Count; i++)&lt;br&gt;
{&amp;nbsp;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
Run through the sites&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; j=0;
j&amp;lt;vServers[i].Sites.Count; j++)&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&lt;/span&gt;(vServers[i].Sites[j].Url
== predefinedUrl)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
Do some logic ...&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Option 3 :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SPGlobalAdmin
globalAdmin &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SPGlobalAdmin();&lt;br&gt;
SPVirtualServerCollection vServers &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; globalAdmin.VirtualServers; 
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through the virtual servers&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt;vServers.Count; i++)&lt;br&gt;
{&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;SPVirtualServer vs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; vServers[i];&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
Run through the sites&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; j=0;
vs.Sites.Count; j++)&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPSite s &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; vs.Sites[j];&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&lt;/span&gt;(s.Url
== predefinedUrl)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//
Do some logic ...&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
So, what's wrong with this practices ?&lt;br&gt;
the problem lays in the way the object model is implemented : Unmanaged code - which
means that you &lt;strong&gt;must&lt;/strong&gt; to release memory explicitly.&lt;br&gt;
garbage collector will not handle these object, and you must handle it in your code.
&lt;/p&gt;
&lt;p&gt;
problems in option 1 :
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
implementing this practice (please don't), will cause memory leaks, due to a fact
that dispose() method is not being used, and memory is not being released. 
&lt;li&gt;
Exception management - suppose you will call the dispose method of the SPSite object
and the end of the foreach loop, 
&lt;br&gt;
what will happen if an exception occur ?&lt;br&gt;
the memory allocated to the object will not be released, and the garbage collector
won't release it either, causing memory leaks each time exception takes place. 
&lt;li&gt;
Even if you decide to include some exception management code (try-catch for example),
the given object won't be reachable because it lives&amp;nbsp;in it's own scope (the foreach
scope).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Problems in option 2 :
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
implementing this practice (just like the 1st option), will cause memory leaks, due
to a fact that dispose() method is not being used, and memory is not being released. 
&lt;li&gt;
reading the previews statement probably raise some reasonable question : 
&lt;br&gt;
"hey, I'm not creating any new objects, and does not allocating any memory, just accessing
some property in a given collection, what is the problem here ?"&lt;br&gt;
this is a question i asked myself too, so i dug deep through it, and found that the
sites in the Sites collection that lays in a virtual server object is not being created
until you reference them explicitly - which means : accessing their properties or
getting an outer reference to some site through a variable.&lt;br&gt;
so when accessing a property will cause memory allocation behind the scenes. 
&lt;li&gt;
calling the dispose method like so :&lt;br&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Sites[i].Dispose();&lt;/span&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;will not release the memory.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maybe its related to the fact
that the Sites[i] object is defined as "read-only" .&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if you find the reason for that
please let me know.
&lt;/p&gt;
&lt;p&gt;
Problems in option 3 :
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
OK, i must admit, this looks much better than the ones mentioned above, but still
lack of some memory releasing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
How can we write it right ?&lt;br&gt;
here is an example of what i consider as a good practice :
&lt;/p&gt;
&lt;p&gt;
Option 4:&lt;br&gt;
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Wrap the globalAdmin object in a using scope - this object is unmanaged&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt;(SPGlobalAdmin
globalAdmin &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; SPGlobalAdmin())&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Get the virtual servers collection reference&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPVirtualServerCollection vServers &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; globalAdmin.VirtualServers;&amp;nbsp;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through the virtual servers&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt;vServers.Count; i++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPVirtualServer vs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; vServers[i];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Run through the sites&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; j=0;
vs.Sites.Count; j++) 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Wrap the SPSite object in a using scope - this object is unmanaged&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt;(SPSite
s &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; vs.Sites[j])&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(s.Url
== predefinedUrl)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Do some logic ...&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Make sure that this objects memory will be cleared by the GC&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vs &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Call the garbage collector and make sure that the memory is released&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GC.Collect();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GC.WaitForPendingFinalizers();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
as you can see, unmanaged object is wrapped in a using scope,&lt;br&gt;
and the GC(garbage collector) is being activated manually.
&lt;/p&gt;
&lt;p&gt;
changing from one of the bad practices to this one improved dramatically performance.&lt;br&gt;
for example :&lt;br&gt;
iterating with option number 2 caused the w3wp.exe process (that is the IIS process)
to reach 1200 MB and crash (reaching the given limit) after iterating through 2700
sites,&lt;br&gt;
while implementing option 4, i didn't saw any dramatic changes in the process info,
and it stayed at 87 MB only and iterated through all the sites, a total of 8876 sites.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=7aac8381-fee7-41b8-96a0-fe2dfbf589e2" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,7aac8381-fee7-41b8-96a0-fe2dfbf589e2.aspx</comments>
      <category>.Net</category>
      <category>Microsoft/SPS (sharepoint server)</category>
      <category>Performance</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=7c22ef12-b6f2-46e1-9c70-6cadfebbc349</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,7c22ef12-b6f2-46e1-9c70-6cadfebbc349.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,7c22ef12-b6f2-46e1-9c70-6cadfebbc349.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7c22ef12-b6f2-46e1-9c70-6cadfebbc349</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>writing secure .Net code for web applications - Prologue</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,7c22ef12-b6f2-46e1-9c70-6cadfebbc349.aspx</guid>
      <link>http://www.krokhmal.com/2006/09/27/writingSecureNetCodeForWebApplicationsPrologue.aspx</link>
      <pubDate>Wed, 27 Sep 2006 17:41:45 GMT</pubDate>
      <description>&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;Today I stepped
into my parallel team office just when &lt;a href="http://www.human-debugger.net/"&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;shani
raba&lt;/span&gt;&lt;/a&gt;&amp;nbsp;(AKA - "human debugger") explained to a new programmer the usage
of validators in ASP.NET form.&lt;br&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
We started an argument about the affectivity of the .Net built-in validators, and
what should you do besides that on the server side, to guarantee no security breaches
through that tiny input that protected by the "mighty" .Net Validator.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;We came to several
interesting conclusions and understanding about aspect of the subject that we didn't
knew.&lt;br&gt;
So, I decided to write a post about that, 
&lt;br&gt;
I came home, and started to write some example on the subject.&lt;br&gt;
The problem is that as soon as I started to cover one aspect of the subject, other
aspects came across that I couldn't neglect.&lt;br&gt;
So I decided to create several posts during this week and the next, which will cover
most of the "secure .Net code for web applications" subject.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;The posts will
refer to:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;ul type=disc&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Cross-site scripting (XSS) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Session hijacking 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Hidden field tampering 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;SQL injection 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Cookies and Authentication 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;some other aspects that I'll encounter
on the way 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Your requests... 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt 0.5in; COLOR: #003300; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 12pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left; mso-margin-top-alt: auto"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana"&gt;So stay tuned
for the next weeks for more about the subject.&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; DIRECTION: ltr; unicode-bidi: embed; TEXT-ALIGN: left"&gt;
&lt;o:p&gt;
&lt;font face="Times New Roman" color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=7c22ef12-b6f2-46e1-9c70-6cadfebbc349" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,7c22ef12-b6f2-46e1-9c70-6cadfebbc349.aspx</comments>
      <category>.Net</category>
      <category>Security</category>
      <category>XSS</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=9692feeb-b910-4855-aa0b-1a42e83ab8dc</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,9692feeb-b910-4855-aa0b-1a42e83ab8dc.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,9692feeb-b910-4855-aa0b-1a42e83ab8dc.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9692feeb-b910-4855-aa0b-1a42e83ab8dc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
the main reason that I've started to play with threads is because the industry WILL
(sooner or later) move to a multi-core guided programing, and it WILL become mainstream
(mark my words :) ).
</p>
        <p>
any way, lets start from the beginning, and why do we need threads.<br />
according to the <a href="http://en.wikipedia.org/wiki/Multi-threading">definition</a> :
"Threads are a way for a program to split itself into two or more simultaneously (or
pseudo-simultaneously) running tasks. Threads and processes differ from one operating
system to another, but in general, the way that a thread is created and shares its
resources is different from the way a process does."
</p>
        <p>
so, in other words, we will use threads when we need to perform simultaneous tasks.<br />
these kind of actions made when you have unused processing time while waiting for
other task to finish.<br /><br />
so, back to the .Net world, how would we do that ?
</p>
        <p>
to use threads, we need to include the library :
</p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p class="HighlightedCode">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</span> System.Threading;</span>
          </p>
        </span>
        <p>
the next thing we need i to know how to to lunch a thread with a task.
</p>
        <ul>
          <li>
we need to create a task to be done. 
</li>
          <li>
a <a href="http://msdn2.microsoft.com/en-us/library/system.threading.threadstart.aspx">ThredStart
delegate</a> which will point to our task. 
</li>
          <li>
a new thread ( or an old one from a thread pool ) - which is better and when will
be explained in some later posts. 
</li>
          <li>
start the thread.</li>
        </ul>
        <p>
so :
</p>
        <p>
lets create some task :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> BurnCPUwithOneThread()<br />
        {<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i=0;
i&lt; 5000000;i++)<br />
            {<br />
                lblcounter.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> i.ToString();<br />
            }<br />
        }</span>
        </p>
        <p>
 
</p>
        <p>
and one more :
</p>
        <p class="HighlightedCode">
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        private</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> BurnCPUwithTwoThreads()<br />
        {<br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i=0;
i&lt; 5000000;i++)<br />
            {<br />
                lblCounter2.Text <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> i.ToString();<br />
            }<br />
        }</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" size="2">now
we will create the delegate and the threads, and activate them.</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p class="HighlightedCode">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> button4_Click(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
System.EventArgs e)<br />
        {<br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//We
will run the action in a different thread from the gui</span><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//so
when we do sleep the the tread the gui will not hang up.</span><br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Create the thread start object</span><br />
            ThreadStart
ts <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ThreadStart(BurnCPUwithOneThread);<br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
The tread itself</span><br />
            Thread t <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Thread(ts);<br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Starting the thread</span><br />
            t.Start();<br /><br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Create the thread start object</span><br />
            ThreadStart
ts2 <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ThreadStart(BurnCPUwithTwoThreads);<br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
The tread itself</span><br />
            Thread t2 <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Thread(ts2);<br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Starting the thread</span><br />
            t2.Start();<br /><br />
        }</span>
          </p>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            </span> 
</p>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  <font face="Verdana" size="2">thats
it.<br />
   now you have a working little program with 2 threads.<br />
   if you will run this code , you will notice that it is done simultaneously.</font></span>
          </p>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" size="2">
                <br />
   next lessons will handle : sending parameters to threads, synchronizing,
thread pool, and more.<br />
   please comment, if you would like me to focus on some specific subject...<br /></font>
            </span>
          </p>
        </span>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=9692feeb-b910-4855-aa0b-1a42e83ab8dc" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Coding with Threads in .Net - Lesson 1</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,9692feeb-b910-4855-aa0b-1a42e83ab8dc.aspx</guid>
      <link>http://www.krokhmal.com/2006/09/25/CodingWithThreadsInNetLesson1.aspx</link>
      <pubDate>Mon, 25 Sep 2006 17:28:14 GMT</pubDate>
      <description>&lt;p&gt;
the main reason that I've started to play with threads is because the industry WILL
(sooner or later) move to a multi-core guided programing, and it WILL become mainstream
(mark my words :) ).
&lt;/p&gt;
&lt;p&gt;
any way, lets start from the beginning, and why do we need threads.&lt;br&gt;
according to the &lt;a href="http://en.wikipedia.org/wiki/Multi-threading"&gt;definition&lt;/a&gt;&amp;nbsp;:
"Threads are a way for a program to split itself into two or more simultaneously (or
pseudo-simultaneously) running tasks. Threads and processes differ from one operating
system to another, but in general, the way that a thread is created and shares its
resources is different from the way a process does."
&lt;/p&gt;
&lt;p&gt;
so, in other words, we will use threads when we need to perform simultaneous tasks.&lt;br&gt;
these kind of actions made when you have unused processing time while waiting for
other task to finish.&lt;br&gt;
&lt;br&gt;
so, back to the .Net world, how would we do that ?
&lt;/p&gt;
&lt;p&gt;
to use threads, we need to include the library :
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Threading;&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
the next thing we need i to know how to to lunch a thread with a task.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
we need to create a task to be done. 
&lt;li&gt;
a &lt;a href="http://msdn2.microsoft.com/en-us/library/system.threading.threadstart.aspx"&gt;ThredStart
delegate&lt;/a&gt; which will point to our task. 
&lt;li&gt;
a new thread ( or an old one from a thread pool ) - which is better and when will
be explained in some later posts. 
&lt;li&gt;
start the thread.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
so :
&lt;/p&gt;
&lt;p&gt;
lets create some task :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; BurnCPUwithOneThread()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt; 5000000;i++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblcounter.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; i.ToString();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
and one more :
&lt;/p&gt;
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; BurnCPUwithTwoThreads()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;for&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; i=0;
i&amp;lt; 5000000;i++)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblCounter2.Text &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; i.ToString();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana size=2&gt;now
we will create the delegate and the threads, and activate them.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p class=HighlightedCode&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; button4_Click(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
System.EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//We
will run the action in a different thread from the gui&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//so
when we do sleep the the tread the gui will not hang up.&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Create the thread start object&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ThreadStart
ts &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; ThreadStart(BurnCPUwithOneThread);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
The tread itself&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread t &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Thread(ts);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Starting the thread&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;t.Start();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Create the thread start object&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ThreadStart
ts2 &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; ThreadStart(BurnCPUwithTwoThreads);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
The tread itself&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread t2 &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Thread(ts2);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Starting the thread&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;t2.Start();&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&lt;font face=Verdana size=2&gt;thats
it.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;now you have a working little program with 2 threads.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;if you will run this code , you will notice that it is done simultaneously.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana size=2&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;next lessons will handle&amp;nbsp;: sending parameters to threads, synchronizing,
thread pool, and more.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;please comment, if you would like me to focus on some specific subject...&lt;br&gt;
&lt;/p&gt;
&gt;&lt;/span&gt;&gt;&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=9692feeb-b910-4855-aa0b-1a42e83ab8dc" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,9692feeb-b910-4855-aa0b-1a42e83ab8dc.aspx</comments>
      <category>.Net</category>
      <category>Lessons</category>
      <category>Performance</category>
      <category>Threading</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=b9e91ee5-f29d-4a36-8b67-ed40eb72920b</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,b9e91ee5-f29d-4a36-8b67-ed40eb72920b.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,b9e91ee5-f29d-4a36-8b67-ed40eb72920b.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b9e91ee5-f29d-4a36-8b67-ed40eb72920b</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While surfing the net for some new hardware tech toys, i encountered an article
about <a href="http://www.techpowerup.com/index.php?16248">multi-core guided software
architecture</a>.
</p>
        <p>
"Intel's support in multi-core education is critical for two reasons," said Karsten
Schwan, professor of College of Computing, Georgia Institute of Technology. "First,
getting early access to advanced technology and new equipment is something that always
excites students. Second, companies like Intel have a perspective that looks beyond
research to see the broader potential for technology."
</p>
        <p>
For us, it means changing the whole perception of software architecture, design and
implementation such as parallelism, threading concepts, threading methodology and
programming with threads 
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=b9e91ee5-f29d-4a36-8b67-ed40eb72920b" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>A new era in software architecture - Multi-Core guided</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,b9e91ee5-f29d-4a36-8b67-ed40eb72920b.aspx</guid>
      <link>http://www.krokhmal.com/2006/08/26/ANewEraInSoftwareArchitectureMultiCoreGuided.aspx</link>
      <pubDate>Sat, 26 Aug 2006 00:47:58 GMT</pubDate>
      <description>&lt;p&gt;
While surfing the net for some new hardware tech toys, i encountered&amp;nbsp;an article
about &lt;a href="http://www.techpowerup.com/index.php?16248"&gt;multi-core guided software
architecture&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
"Intel's support in multi-core education is critical for two reasons," said Karsten
Schwan, professor of College of Computing, Georgia Institute of Technology. "First,
getting early access to advanced technology and new equipment is something that always
excites students. Second, companies like Intel have a perspective that looks beyond
research to see the broader potential for technology."
&lt;/p&gt;
&lt;p&gt;
For us, it means changing the whole perception of software architecture, design and
implementation such as parallelism, threading concepts, threading methodology and
programming with threads 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=b9e91ee5-f29d-4a36-8b67-ed40eb72920b" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,b9e91ee5-f29d-4a36-8b67-ed40eb72920b.aspx</comments>
      <category>.Net</category>
      <category>Performance</category>
      <category>Threading</category>
    </item>
    <item>
      <trackback:ping>http://www.krokhmal.com/Trackback.aspx?guid=eb16227a-d2aa-40af-9d45-aace858ffb8e</trackback:ping>
      <pingback:server>http://www.krokhmal.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.krokhmal.com/PermaLink,guid,eb16227a-d2aa-40af-9d45-aace858ffb8e.aspx</pingback:target>
      <dc:creator>Shimon krokhmal</dc:creator>
      <wfw:comment>http://www.krokhmal.com/CommentView,guid,eb16227a-d2aa-40af-9d45-aace858ffb8e.aspx</wfw:comment>
      <wfw:commentRss>http://www.krokhmal.com/SyndicationService.asmx/GetEntryCommentsRss?guid=eb16227a-d2aa-40af-9d45-aace858ffb8e</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
when planning a software solution, one of the most important things is to design the
solution the best way it can be,<br />
even before writing the first line of code, we need to know exactly how we should
implement it.
</p>
        <p>
so what would you do if you never planned/worked/implemented such type of a solution
?
</p>
        <p>
needless to say that inventing the wheel all over again will be unnecessary ,<br />
first you consult with the "elders" (the more experienced co-workers),<br />
trying maybe google up the solution,<br />
going over the references and the guide lines in developing this kind of a solution
or at the given platform,<br />
starting some thinking team and so ...
</p>
        <p>
finally, you came up with a solution, and....<br />
start implementing it.
</p>
        <p>
now, in a perfect world, once you did the steps mentioned above, you have a perfect
solution.<br />
but in the real world, something must to go wrong.
</p>
        <p>
recently i came across some interesting example of this phenomena.<br />
while designing a "file Version manager solution" on SPS (Share point Server) platform,<br />
following the SPS development guidelines, which says that you (the developer), should <strong>never </strong>approach
the SPS database.<br /><strong>always</strong>, but <strong>always </strong>get the data through the object
model.<br /><br />
so, by doing that, you came up with a working application,but..... catastrophic performance.<br />
after consulting with other staff, we came to the conclusion that the bottleneck is
in the object model itself.<br />
so the only thing we had to do is the direct approach to the database ( a big NO NO
on the guide lines).<br />
and apparently the performance graph suddenly got a dramatic change (better performance).
</p>
        <p>
i think that guide lines did not meant to become laws, but to be just as a suggestions
to most of the cases.<br />
what do you think about this issue ?
</p>
        <img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=eb16227a-d2aa-40af-9d45-aace858ffb8e" />
        <br />
        <hr />
Shimon krokhmal, a part of the Krokhmal family</body>
      <title>Does following Microsoft guidelines(or any guidelines..), is Always a good idea ?</title>
      <guid isPermaLink="false">http://www.krokhmal.com/PermaLink,guid,eb16227a-d2aa-40af-9d45-aace858ffb8e.aspx</guid>
      <link>http://www.krokhmal.com/2006/08/17/DoesFollowingMicrosoftGuidelinesorAnyGuidelinesIsAlwaysAGoodIdea.aspx</link>
      <pubDate>Thu, 17 Aug 2006 20:54:25 GMT</pubDate>
      <description>&lt;p&gt;
when planning a software solution, one of the most important things is to design the
solution the best way it can be,&lt;br&gt;
even before writing the first line of code, we need to know exactly how we should
implement it.
&lt;/p&gt;
&lt;p&gt;
so what would you do if you never planned/worked/implemented such type of a solution
?
&lt;/p&gt;
&lt;p&gt;
needless to say that inventing the wheel all over again will be unnecessary ,&lt;br&gt;
first you consult with the "elders" (the more experienced co-workers),&lt;br&gt;
trying maybe google up the solution,&lt;br&gt;
going over the references and the guide lines in developing this kind of a solution
or at the given platform,&lt;br&gt;
starting some thinking team and so ...
&lt;/p&gt;
&lt;p&gt;
finally, you came up with a solution, and....&lt;br&gt;
start implementing it.
&lt;/p&gt;
&lt;p&gt;
now, in a perfect world, once you&amp;nbsp;did the steps mentioned above, you have a perfect
solution.&lt;br&gt;
but in the real world, something must to go wrong.
&lt;/p&gt;
&lt;p&gt;
recently i came across some interesting example of this phenomena.&lt;br&gt;
while designing a "file Version manager solution" on SPS (Share point Server) platform,&lt;br&gt;
following the SPS development guidelines, which says that you (the developer), should &lt;strong&gt;never &lt;/strong&gt;approach
the SPS database.&lt;br&gt;
&lt;strong&gt;always&lt;/strong&gt;, but &lt;strong&gt;always &lt;/strong&gt;get the data through the object
model.&lt;br&gt;
&lt;br&gt;
so, by doing that, you came up with a working application,but..... catastrophic performance.&lt;br&gt;
after consulting with other staff, we came to the conclusion that the bottleneck is
in the object model itself.&lt;br&gt;
so the only thing we had to do is the direct approach to the database ( a big NO NO
on the guide lines).&lt;br&gt;
and apparently the performance graph suddenly got a&amp;nbsp;dramatic change (better performance).
&lt;/p&gt;
&lt;p&gt;
i think that guide lines did not meant to become laws, but to be just as a suggestions
to most of the cases.&lt;br&gt;
what do you think about this issue ?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.krokhmal.com/aggbug.ashx?id=eb16227a-d2aa-40af-9d45-aace858ffb8e" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Shimon krokhmal, a part of the Krokhmal family</description>
      <comments>http://www.krokhmal.com/CommentView,guid,eb16227a-d2aa-40af-9d45-aace858ffb8e.aspx</comments>
      <category>.Net</category>
      <category>Architectural solutions</category>
      <category>Microsoft/SPS (sharepoint server)</category>
      <category>Microsoft</category>
    </item>
  </channel>
</rss>