<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://interactiveasp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'C# 3.0'</title><link>http://interactiveasp.net/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=C%23+3.0&amp;orTags=0</link><description>Search results matching tag 'C# 3.0'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008 (Build: 30417.1769)</generator><item><title>Understanding Lambda Expressions</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2009/01/20/understanding-lambda-expressions.aspx</link><pubDate>Tue, 20 Jan 2009 20:20:00 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:391</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;This post has been sitting in my drafts for months!&amp;nbsp; Because my friend Phil just posted his &lt;a target="_blank" href="http://interactiveasp.net/blogs/spgilmore/archive/2009/01/09/lambda-expressions-tutorial-for-c-and-visual-studio-2008.aspx"&gt;post on Lambda Expressions&lt;/a&gt; I'll simply link to his post and present the rest of this as supplemental examples. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;span style="color: green"&gt;// Delegates&lt;br /&gt;&lt;span style="color: green"&gt;// My Blog Engine is having trouble showing these so there may be some extra spaces&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;public delegate &lt;/span&gt;&lt;span style="color: #000000;"&gt;IntMathExpression (&lt;span style="color: blue"&gt;int &lt;/span&gt;x, &lt;span style="color: blue"&gt;int &lt;/span&gt;y);&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;&lt;span style="color: #0000ff;"&gt;public delegate &lt;/span&gt;&lt;span style="color: #000000;"&gt;IntMathExpressionSingle (&lt;span style="color: blue"&gt;int &lt;/span&gt;x);&lt;br /&gt;&lt;/span&gt;public delegate &lt;/span&gt;&lt;span style="color: #000000;"&gt;FloatMathExpression (&lt;span style="color: blue"&gt;float &lt;/span&gt;x, &lt;span style="color: blue"&gt;float &lt;/span&gt;y);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Basic Lamda Expression
&lt;/span&gt;IntMathExpression a = (&lt;span style="color: blue"&gt;int &lt;/span&gt;x, &lt;span style="color: blue"&gt;int &lt;/span&gt;y) =&amp;gt; x * y;
IntMathExpression b = (&lt;span style="color: blue"&gt;int &lt;/span&gt;alpha, &lt;span style="color: blue"&gt;int &lt;/span&gt;brovo) =&amp;gt; alpha * brovo;
IntMathExpressionSingle c = (&lt;span style="color: blue"&gt;int &lt;/span&gt;x) =&amp;gt; x * x;

&lt;span style="color: green"&gt;// "such that" =&amp;gt; 
// Parameters       =&amp;gt; function body
// (param1, param2) =&amp;gt; param1 + param2

// Lamda Expression using Type Inference
&lt;/span&gt;FloatMathExpression d = (x, y) =&amp;gt; x + 3.14f * y;
&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: #008000;"&gt;// There is usually no need for custom delegates&lt;br /&gt;&lt;/span&gt;Func&amp;lt;&lt;span style="color: blue"&gt;float&lt;/span&gt;, &lt;span style="color: blue"&gt;float&lt;/span&gt;, &lt;span style="color: blue"&gt;float&lt;/span&gt;&amp;gt; e = (x, y) =&amp;gt; x * 100.0f + y;

&lt;span style="color: green"&gt;// Example using a lamda expression
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; primes = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;() { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };
&lt;span style="color: blue"&gt;var &lt;/span&gt;p = primes.Where( prime =&amp;gt; prime.ToString().EndsWith( &lt;span style="color: #a31515"&gt;"3" &lt;/span&gt;) );

&lt;span style="color: green"&gt;// Deferred Execution
&lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i &lt;span style="color: blue"&gt;in &lt;/span&gt;p) {
    MessageBox.Show(i.ToString());
}

&lt;span style="color: green"&gt;// Query Expression Format
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;p2 = &lt;span style="color: blue"&gt;from &lt;/span&gt;prime &lt;span style="color: blue"&gt;in &lt;/span&gt;primes
         &lt;span style="color: blue"&gt;where &lt;/span&gt;prime.ToString().EndsWith(&lt;span style="color: #a31515"&gt;"3"&lt;/span&gt;)
         &lt;span style="color: blue"&gt;select &lt;/span&gt;prime;

&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; results = p2.ToList();

&lt;span style="color: green"&gt;// Lamda Expressions mixed with Extension Methods
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; str = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;() { &lt;span style="color: #a31515"&gt;"The Lord of the Rings"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Star Wars, Eposode III"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Ratatouille" &lt;/span&gt;};

&lt;span style="color: blue"&gt;var &lt;/span&gt;p3 = &lt;span style="color: blue"&gt;from &lt;/span&gt;movie &lt;span style="color: blue"&gt;in &lt;/span&gt;str
         &lt;span style="color: blue"&gt;where &lt;/span&gt;movie.CountVowels() &amp;gt; 5
         &lt;span style="color: blue"&gt;select &lt;/span&gt;movie;

&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; movieResults = p3.ToList();&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Bug in Visual Studio 2008 SP1?</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/09/15/bug-is-visual-studio-2008-sp1.aspx</link><pubDate>Mon, 15 Sep 2008 17:25:00 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:85</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;This is just a quick post.&amp;nbsp; I had a bug where any time I tried to compile a WPF project on my laptop I got the following pair of errors:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Error Message 1:&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;The &amp;quot;SplashScreen&amp;quot; parameter is not supported by the &amp;quot;MarkupCompilePass1&amp;quot; task. Verify the parameter exists on the task, and it is a settable public instance property.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Error Message 2:&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;The &amp;quot;MarkupCompilePass1&amp;quot; task could not be initialized with its input parameters.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I completely uninstalled Visual Studio 2008 &amp;amp; SP1 and reinstalled everything and this did not go away.&amp;nbsp; Anyway, here is how you fix it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Using a text editor, open the file: &lt;strong&gt;C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.WinFx.targets&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Search for &amp;quot;&lt;strong&gt;MarkupCompilePass1&lt;/strong&gt;&amp;quot;; this was line 294 for me&lt;/li&gt;
&lt;li&gt;Remove the following line from the XML tag line: &lt;strong&gt;SplashScreen=&amp;quot;@(SplashScreen)&amp;quot;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have also posted my work around on the Microsoft Connect site (link below).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361596" title="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361596"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361596&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=364103" title="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=364103"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=364103&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>.NET Threading :: Part 1 - Basic Threading</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/09/09/net-threading-part-1-basic-threading.aspx</link><pubDate>Tue, 09 Sep 2008 19:18:28 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:71</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/Threading_5F00_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;margin:0px 10px 5px 0px;border-left:0px;border-bottom:0px;" border="0" alt="Threading" align="left" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/Threading_5F00_thumb.png" width="172" height="71" /&gt;&lt;/a&gt; Recently I have been doing a lot with threading.&amp;nbsp; This is a concept that used to be very difficult for me and now is only just difficult! &lt;img alt="smile_regular" src="http://spaces.live.com/rte/emoticons/smile_regular.gif" /&gt;&amp;nbsp; Threading is becoming increasingly important as modern processors are not getting faster, they are getting more cores.&amp;nbsp; In order for a application to utilize any of the power of modern CPU&amp;#39;s it must use threading! So I thought I would take a second and go through all of the classes in the System.Threading namespace.&amp;nbsp; We&amp;#39;ll start with the simple stuff and move on to more advanced stuff!&lt;/p&gt; &lt;p&gt;The most familiar and basic structure for locking in .net is the lock statement shown below:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;lock &lt;/span&gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt;) {
    ObjectCount = value;
}
&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;The lock is a simple synchronization structure which will only allow a single thread into the &amp;quot;critical&amp;quot; locked section at a time.&amp;nbsp; Many people don&amp;#39;t realize this but the following code does the exact same thing:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Monitor&lt;/span&gt;.Enter(&lt;span style="color:blue;"&gt;this&lt;/span&gt;);
    ObjectCount = value;
&lt;span style="color:#2b91af;"&gt;Monitor&lt;/span&gt;.Exit(&lt;span style="color:blue;"&gt;this&lt;/span&gt;);&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;In fact, the Monitor object can do a lot more than enter a critical section; though I&amp;#39;ve not found a lot of use for the other functions.&amp;nbsp; But some operations of note are Monitor.TryEnter which allows you to specify a time span to wait for the lock.&amp;nbsp; Monitor.Pulse and Monitor.PulseAll notify the next waiting thread or all waiting threads respectively that a lock has been released.&amp;nbsp; This is not necessarily required but may result in the next thread being able to enter the critical section a bit quicker.&amp;nbsp; Monitor.Wait will release the lock to let another thread enter and then re-acquire the lock.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Another note-worthy threading trick is the keyword &lt;strong&gt;volatile&lt;/strong&gt;. This designation is useful in conditions where we are waiting for a variable to be changed in a while loop.&amp;nbsp; The C# compiler is really smart and usually assumed volatility for you, but it&amp;#39;s a great habit to use it explicitly.&amp;nbsp; Basically what it does is it does not allow the value of a variable to be cached in a register or a stack.&amp;nbsp; Any time the value is referenced it will be pulled from it&amp;#39;s memory location on the stack.&amp;nbsp; If this were not the case the value could change and you may never break out of the while loop.&amp;nbsp; Here is a quick example:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private volatile bool &lt;/span&gt;IsCanceled;

&lt;span style="color:blue;"&gt;private void &lt;/span&gt;RunThread(&lt;span style="color:blue;"&gt;object &lt;/span&gt;state) {
    &lt;span style="color:blue;"&gt;while &lt;/span&gt;(!IsCanceled) {
        &lt;span style="color:green;"&gt;// Do work here!
    &lt;/span&gt;}
}&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;In the code block above, if some other thread changes the state of IsCanceled then the while loop will stop and the thread will exit.&amp;nbsp; While this is the behavior you would expect anyway the compiler might not agree with you (especially if there is late-binding or the value is modified outside of the scope of the class).&amp;nbsp; This keyword only works on fields, not properties and should only be used where it must as it will adversely affect performance.&amp;nbsp; Again, it&amp;#39;s just good practice to use it when reading a value that can be mutated by another thread.&lt;/p&gt;
&lt;p&gt;One of my favorite patterns is the singleton pattern.&amp;nbsp; This pattern is the most widely recognized but the least understood.&amp;nbsp; Lets take a second to examine a standard implementation of the singleton pattern.&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass &lt;/span&gt;{

    &lt;span style="color:blue;"&gt;private static volatile &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass &lt;/span&gt;_instance = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;

    &lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass &lt;/span&gt;Instance {
        &lt;span style="color:blue;"&gt;get &lt;/span&gt;{
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_instance == &lt;span style="color:blue;"&gt;null&lt;/span&gt;) {
                &lt;span style="color:blue;"&gt;lock &lt;/span&gt;(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;SingletonExampleClass&lt;/span&gt;)) {
                    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_instance == &lt;span style="color:blue;"&gt;null&lt;/span&gt;) {
                        _instance = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass&lt;/span&gt;();
                    }
                }
            }
            &lt;span style="color:blue;"&gt;return &lt;/span&gt;_instance;
        }
    }
}&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;As you can see from the code above we have to implement double-checking.&amp;nbsp; The reason is that after the evaluation another thread could be slightly ahead and have created the object just ahead of you.&amp;nbsp; You &lt;strong&gt;could&lt;/strong&gt; lock the type before doing your check in the first place but locking is expensive and completely unnecessary most of the times.&amp;nbsp; Only the first call requires the lock, after that all other calls simply want an a reference to that class.&amp;nbsp; Singleton is a very important pattern for serialization and is one of the most common, that&amp;#39;s why Microsoft gave us a break here with the &lt;strong&gt;readonly&lt;/strong&gt; keyword.&amp;nbsp; The same section of code above can be written as:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass &lt;/span&gt;{

    &lt;span style="color:blue;"&gt;public static readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass &lt;/span&gt;Instance = &lt;/pre&gt;&lt;pre class="code"&gt;        &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SingletonExampleClass&lt;/span&gt;();

}&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Much simpler! It literally eliminated 12 lines of code!&amp;nbsp; This is more or less the same as it&amp;#39;s brother.&amp;nbsp; The only difference is the lazy instantiation in the first example, but in almost all cases this pattern is simpler and more intuitive.&amp;nbsp; This pattern is also a little more flexible as it will allow you to use readonly on non-static fields as well.&amp;nbsp; Additionally you may instantiate the value in the constructor rather than the initializer, but you must do one or the other.&amp;nbsp; Also, once the value is set it may not be changed!&lt;/p&gt;
&lt;p&gt;Another favorite of mine is the &lt;strong&gt;Interlocked&lt;/strong&gt; class.&amp;nbsp; Interlocked.Increment and Interlocked.Decrement allows you to increment or decrement an numeric value using a thread-safe mechanism.&amp;nbsp; &lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private int &lt;/span&gt;ItemsProcessed = 0;

&lt;span style="color:blue;"&gt;private void &lt;/span&gt;RunThread(&lt;span style="color:blue;"&gt;object &lt;/span&gt;state) {
    &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;Order&amp;gt; orders = state &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;Order&amp;gt;;
    
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;( orders == &lt;span style="color:blue;"&gt;null &lt;/span&gt;)
        &lt;span style="color:blue;"&gt;return&lt;/span&gt;;

    &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(Order ord &lt;span style="color:blue;"&gt;in &lt;/span&gt;orders) {
        &lt;span style="color:green;"&gt;// Process Order
        // ...
        &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Interlocked&lt;/span&gt;.Increment(&lt;span style="color:blue;"&gt;ref &lt;/span&gt;ItemsProcessed);
    }
}&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;As you can see, it&amp;#39;s pretty simple to&amp;nbsp; use.&amp;nbsp; You may be wondering about the use of &lt;strong&gt;ref&lt;/strong&gt; in the function signature.&amp;nbsp; Well, as you know int and long are value types (structs) and would be passed to any function by value (copying the contents to the function).&amp;nbsp; When we use the ref function signature it tells the compiler that we don&amp;#39;t want to pass a copy of this value to the function, we want to pass the actual variable.&amp;nbsp; I.E. we passed a pointer to the variable rather than the value of it. This means that any mutations made to the variable inside of the function are effective outside of the function.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The next basic structure I&amp;#39;d like to discuss is a &lt;strong&gt;Mutex&lt;/strong&gt;.&amp;nbsp; A Mutex is a lot like the Monitor object I showed above and a ManualResetEvent but can work between different processes, not just different threads.&amp;nbsp; The specifics of a Mutex are best described in this snippit from the MSDN documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;div id="ctl00_LibFrame_ra1" class="resizableArea"&gt;
&lt;div id="ctl00_LibFrame_raRight" class="rightSection"&gt;
&lt;div id="mainSection"&gt;
&lt;div id="mainBody"&gt;
&lt;div class="topic"&gt;
&lt;div id="mainSection"&gt;
&lt;div id="mainBody"&gt;
&lt;div id="ctl00_LibFrame_MainContent_cpe81511" class="MTPS_CollapsibleRegion"&gt;
&lt;div style="overflow:visible;width:auto;display:block;height:auto;" id="ctl00_LibFrame_MainContent_cpe81511_c" class="MTPS_CollapsibleSection"&gt;
&lt;div style="border-right:medium none;border-top:medium none;border-left:medium none;border-bottom:medium none;display:block;" class="MTPS_CollapsibleSection"&gt;
&lt;p&gt;Mutexes are of two types: local mutexes, which are unnamed, and named system mutexes. A local mutex exists only within your process. It can be used by any thread in your process that has a reference to the &lt;span&gt;&lt;span class="selflink"&gt;Mutex&lt;/span&gt;&lt;/span&gt; object that represents the mutex. Each unnamed &lt;span&gt;&lt;span class="selflink"&gt;Mutex&lt;/span&gt;&lt;/span&gt; object represents a separate local mutex. &lt;/p&gt;
&lt;p&gt;Named system mutexes are visible throughout the operating system, and can be used to synchronize the activities of processes. You can create a &lt;span&gt;&lt;span class="selflink"&gt;Mutex&lt;/span&gt;&lt;/span&gt; object that represents a named system mutex by using a constructor that accepts a name. The operating-system object can be created at the same time, or it can exist before the creation of the &lt;span&gt;&lt;span class="selflink"&gt;Mutex&lt;/span&gt;&lt;/span&gt; object. You can create multiple &lt;span&gt;&lt;span class="selflink"&gt;Mutex&lt;/span&gt;&lt;/span&gt; objects that represent the same named system mutex, and you can use the &lt;span&gt;&lt;a id="ctl00_LibFrame_MainContent_ctl43" href="http://msdn.microsoft.com/en-us/library/system.threading.mutex.openexisting.aspx"&gt;OpenExisting&lt;/a&gt;&lt;/span&gt; method to open an existing named system mutex. &lt;/p&gt;
&lt;div class="alert"&gt;
&lt;table&gt;

&lt;tr&gt;
&lt;th align="left"&gt;&lt;img class="note" title="Note" src="http://i.msdn.microsoft.com/01985e8f.alert_note(en-us,VS.90).gif" alt="" /&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;On a server that is running Terminal Services, a named system mutex can have two levels of visibility. If its name begins with the prefix &amp;quot;Global\&amp;quot;, the mutex is visible in all terminal server sessions. If its name begins with the prefix &amp;quot;Local\&amp;quot;, the mutex is visible only in the terminal server session where it wa s created . In that case, a separate mutex with the same name can exist in each of the other terminal server sessions on the server . If you do not specify a prefix when you create a named mutex , it takes the prefix &amp;quot;Local\&amp;quot;. Within a terminal server session, two mutexes whose names differ only by their prefixes are separate mutexes, and both are visible to all processes in the terminal server session. That is, the prefix names &amp;quot;Global\&amp;quot; and &amp;quot;Local\&amp;quot; describe the scope of the mutex name relative to terminal server sessions, not relative to processes . &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;Here is a short sample that checks for the an existing Mutex and exits if found.&amp;nbsp; This is useful for single-instance applications.&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;static class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Program &lt;/span&gt;{

    &lt;span style="color:blue;"&gt;static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Mutex &lt;/span&gt;m;

    &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color:green;"&gt;The main entry point for the application.
    &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;STAThread&lt;/span&gt;]
    &lt;span style="color:blue;"&gt;static void &lt;/span&gt;Main() {
        &lt;span style="color:green;"&gt;// Check for single instance of our application
        &lt;/span&gt;&lt;span style="color:blue;"&gt;bool &lt;/span&gt;createdNew;
        m = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Mutex&lt;/span&gt;(&lt;span style="color:blue;"&gt;true&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;TestThreadingApplication&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;out &lt;/span&gt;createdNew);
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!createdNew) {&lt;/pre&gt;&lt;pre class="code"&gt;            m.ReleaseMutex();
            &lt;span style="color:blue;"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;pre class="code"&gt;        }
        
        &lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;.EnableVisualStyles();
        &lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;.SetCompatibleTextRenderingDefault(&lt;span style="color:blue;"&gt;false&lt;/span&gt;);
        &lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;.Run(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Form1&lt;/span&gt;());&lt;/pre&gt;&lt;pre class="code"&gt;        m.ReleaseMutex();
    }
}&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;The code works by trying to get an existing Mutex named &amp;quot;TestThreadingApplication&amp;quot;.&amp;nbsp; If that Mutex does not exist in the Operating System it will be created and your thread will be assigned the owner.&amp;nbsp; If you were the first instance you will have created the Mutex and you may resume execution, otherwise your application will exit.&lt;/p&gt;
&lt;p&gt;The last thing we will discuss in this post is a Semaphore.&amp;nbsp; A Semaphore works much the same way as a Mutex, but works best as a way to manage a pool of objects.&amp;nbsp; The Semaphore starts with an initial count of objects.&amp;nbsp; Each time the WaitOne method is called the count will be decrement.&amp;nbsp; When the count reaches zero threads will be blocked until another thread calls Release.&amp;nbsp; Unlike the Mutex, the Semaphore does not track which threads have incremented or decremented the internal count so the programmer must be careful to Release the exact number of times WaitOne is called.&amp;nbsp; It&amp;#39;s best to think of a Semaphore as a synchronization mechanism that can let more than one thread into the critical section.&amp;nbsp; Because of it&amp;#39;s similarity to other synchronization objects I didn&amp;#39;t create a sample code block.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h5&gt;Links:&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms954629.aspx" href="http://msdn.microsoft.com/en-us/library/ms954629.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms954629.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/x13ttww7.aspx" href="http://msdn.microsoft.com/en-us/library/x13ttww7.aspx"&gt;http://msdn.microsoft.com/en-us/library/x13ttww7.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx" href="http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx" href="http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</description></item><item><title>Avoiding Circular Dependencies</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/06/09/avoiding-circular-dependencies.aspx</link><pubDate>Mon, 09 Jun 2008 21:45:06 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:30</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;The term &amp;quot;circular dependency&amp;quot; may be foreign to some programmers (especially if you do Java as it is a pretty common practice).&amp;nbsp; However, anyone who has done some scripting for a referential database knows that you have to run scripts in a certain order.&amp;nbsp; Running scripts out of order causes errors when you run.&amp;nbsp; The interesting trick is that if you run that same incorrectly-ordered DDL script again and again you will eventually get it to run without errors.&amp;nbsp; If you were unaware of the order being incorrect and thought to yourself in that moment &amp;quot;Stupid database!&amp;quot; then this blog post is for you!&lt;/p&gt; &lt;h3&gt;What is a circular dependency? &lt;/h3&gt; &lt;p&gt;It is simply two libraries that use each other (either directly or indirectly) as shown below:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="107" alt="circular depencency" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/circular-depencency_5F00_3.jpg" width="240" border="0" /&gt;&amp;nbsp; &lt;/p&gt; &lt;h6&gt;Figure 1: Circular Dependency&lt;/h6&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image3.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="202" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image3_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt; &lt;h6&gt;Figure 2: Complex Circular Dependency&lt;/h6&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The complexity of a circular dependency may vary.&amp;nbsp; If you are using Visual Studio and have all of your projects loaded into a single solution AND you add Project References (Right click on project -&amp;gt; Add Reference -&amp;gt; Projects Tab -&amp;gt; {Project Name}) then the IDE will not allow you to create Circular Dependencies.&amp;nbsp; In fact, this is a good practice as Visual Studio will ensure the correct build order.&amp;nbsp; &lt;/p&gt; &lt;h3&gt;Why are circular dependencies bad?&lt;/h3&gt; &lt;p&gt;Just like our Database example above, a circular dependency makes it so you can not guarantee that your application has the latest code.&amp;nbsp; That is a big deal!&amp;nbsp; Here is why:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;I make changes to Application 1 (in Figure 2)  &lt;li&gt;I build my project, The changes I made in Application 1 may or may not have gotten into Application 2 (depending on build order).&amp;nbsp; It may have taken a copy of the compiled code that was left over from the last time I built.  &lt;li&gt;Application 2 depends on this new functionality to provide services to Application 3; This functionality will not work correctly with this build.  &lt;li&gt;Application 3 may or may not depend on these same services to provide &lt;strong&gt;back&lt;/strong&gt; to Application 1&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;As you can see in this scenario, there is no such thing as a &amp;quot;correct&amp;quot; build order when there are these circular dependencies.&amp;nbsp; The only way you can arrive at the correct version of the code is to build it as many times as there are nodes in our circle.&amp;nbsp; That would mean for Figure 1 that we would need to build twice and three times for Figure 3.&amp;nbsp; Some of these dependencies can get really ugly!&amp;nbsp; Here is some actual code running in an actual company that I did analysis on some time ago using a tool called &lt;a href="http://www.structure101.com/"&gt;Structure 101&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image9.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="150" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image9_5F00_thumb.png" width="143" border="0" /&gt;&lt;/a&gt; &lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image12.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="199" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image12_5F00_thumb.png" width="218" border="0" /&gt;&lt;/a&gt; &lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image15.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="196" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image15_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image18.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="244" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image18_5F00_thumb.png" width="202" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;How do I fix circular dependencies?&lt;/h3&gt; &lt;p&gt;There are some steps to take to solve even the most complex tangles!&amp;nbsp; They all involve refactoring your code though.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Refactor common code into a &amp;quot;base&amp;quot; dependency; I usually call this &amp;quot;&lt;em&gt;Common&lt;/em&gt;&amp;quot; (figure 3).&amp;nbsp; &lt;strong&gt;&lt;em&gt;BEST SOLUTION&lt;/em&gt;&lt;/strong&gt;  &lt;li&gt;Remove code that is unused.&amp;nbsp; In the tangles shown above many of them are using deprecated/unused code.  &lt;li&gt;Duplicate the sections of code used.&amp;nbsp; This should be seen as a &lt;strong&gt;&lt;em&gt;last resort&lt;/em&gt;&lt;/strong&gt; but given the choice between code duplication and circular dependencies, I take code duplication ever time!&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image21.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="173" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image21_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;br /&gt;&lt;/p&gt; &lt;h6&gt;Figure 3: Refactor a Common&lt;/h6&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;Summary&lt;/h3&gt; &lt;p&gt;There are two kinds of design concepts for nTier (and other types of architectures as well) called &lt;em&gt;Logical Layout Design&lt;/em&gt; and &lt;em&gt;Physical Layout Design&lt;/em&gt;.&amp;nbsp; The Logical Layout is simply that your software occupies the same project/package but leverage different classes.&amp;nbsp; In contrast Physical Layout Design forces each tier to be separated into different Projects/Packages.&amp;nbsp; So long as we are careful to manage the dependencies between these packages from the start this is the preferable way to code.&amp;nbsp; While the logical layout does not suffer from the dependency problem eventually you may wish to break these classes apart and find that there are a lot of inner-dependency that should not exist simply because they occupied the same project.&amp;nbsp; &lt;strong&gt;Remember to keep it clean!&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>XAML Cheat Sheet</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/05/28/xaml-cheat-sheet.aspx</link><pubDate>Thu, 29 May 2008 04:33:05 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:27</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;A few weeks ago I gave a presentation on Silverlight at the &lt;a href="http://www.utcodecamp.com" target="_blank"&gt;Utah Code Camp&lt;/a&gt;.&amp;nbsp; I was really impressed by a presentation I saw last time on Ruby and everyone really liked the cheat sheet that was provided.&amp;nbsp; For my presentation this year I created an XAML Cheat Sheet.&amp;nbsp; For those who are learning XAML it is a pretty good resource but it&amp;#39;s most helpful for me when I know how to do something but I can&amp;#39;t remember the syntax.&amp;nbsp; This is a work in progress so keep on checking back.&amp;nbsp; It can be downloaded in the Media section of this site or by clicking &lt;a href="http://interactiveasp.net/media/p/23/download.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Please drop me a line if you think you have something useful to add or you want to thank me for the hard work it took to put this thing together!&lt;/p&gt; &lt;p&gt;Nathan Zaugg&lt;/p&gt;</description></item><item><title>SP1 for the .Net Framework 3.5 and Visual Studio 2008 Released to Beta</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/05/19/sp1-for-the-net-framework-3-5-and-visual-studio-2008-released-to-beta.aspx</link><pubDate>Mon, 19 May 2008 18:34:00 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:26</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;As promised by Microsoft when Visual Studio 2008 launched late last year, there is a service pack for available both for the .Net framework 3.5 and Visual Studio 2008.&amp;nbsp; Information about the release can be found on &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx"&gt;ScottGu&amp;#39;s Blog&lt;/a&gt; and mostly include bug fixes and performance enhancements, but the points of interest for me are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ASP.NET Routing Engine&lt;/strong&gt; which gives you the ability to map URL&amp;#39;s to route handlers. For example the URL &lt;a href="http://www.mysite.com/myapp/data/234/editComment"&gt;http://www.mysite.com/myapp/data/234/editComment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ASP.NET AJAX Back/Forward Button History Support&lt;/strong&gt; gives you the ability to control the forward &amp;amp; back button clicks on the browser.&amp;nbsp; This will be very useful for &amp;quot;single page&amp;quot; ASP.NET AJAX implementations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance improvements&lt;/strong&gt; on the web editor in VS 2008.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JavaScript Formatting Settings&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CLR performance improvements&lt;/strong&gt; including startup times that are 40% faster and faster ASP.NET requests (up to 10% faster).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WPF New Features and Performance Enhancements!&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Performance enhancements using GPU &lt;/li&gt;
&lt;li&gt;New &amp;quot;WritableBitmap&amp;quot; which allows for tear-free bitmap updates.&lt;/li&gt;
&lt;li&gt;ListBox, ListView, and TreeView now support &amp;quot;item container recycling&amp;quot; and virtualization which results in better performance.&amp;nbsp; This will have a huge effect on large amounts of data.&lt;/li&gt;
&lt;li&gt;Deferred Scrolling which doesn&amp;#39;t render until the mouse up on a scroll event.&amp;nbsp; This will can have a enormous effect on huge data sets.&lt;/li&gt;
&lt;li&gt;StringFormat support within binding expressions&lt;/li&gt;
&lt;li&gt;New Alternating Rows support for controls derived from ItemControl&lt;/li&gt;
&lt;li&gt;Events tab support within the property browser in VS 2008&lt;/li&gt;
&lt;li&gt;Go to Definition and Find All References now support things declared in XAML&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL Server 2008 Support&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;The long awaited &lt;strong&gt;ADO.NET Entity Framework&lt;/strong&gt; which includes integration with any database&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Improvements in WCF&lt;/strong&gt; including scailability, ADO.NET Entities in service contracts, and Improved Debugging support for WCF.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Improvements to C#&lt;/strong&gt;; The C# code editor now identifies and displays red squiggle errors for many semantic code issues that previously required an explicit compilation to identify. The debugger in VS 2008 SP1 has also been improved to provide more debugging support for evaluating LINQ expressions and viewing results at debug time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fixes to TFS&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Installation Cautions&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you are running this on Vista, be sure Vista SP1 is installed!&lt;/li&gt;
&lt;li&gt;If you have installed the VS 2008 Tools for Silverlight 2 Beta1 package on your machine, you must uninstall it - as well as uninstall the KB949325 update for VS 2008 - &lt;em&gt;before &lt;/em&gt;installing VS 2008 SP1 Beta&lt;/li&gt;
&lt;li&gt;If you are running anything earlier than Expression Blend 2.5, then you need to update it to the latest.&amp;nbsp; Earlier versions will cease to run.&lt;/li&gt;
&lt;li&gt;This is still beta software -- Install at your own risk!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A direct download link can also be found here: &lt;a href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx" title="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx"&gt;http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;--Nathan Zaugg&lt;/p&gt;</description></item><item><title>January 2008 NUNUG Notes</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/02/05/january-2008-nunug-notes.aspx</link><pubDate>Tue, 05 Feb 2008 21:40:00 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:9</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;I am a little behind on my Blog but I wanted to be sure and post my notes from January's NUNUG meeting on Visual Studio 2008 and the new features in the C# 3.0 framework.&lt;/p&gt;
&lt;p&gt;I also wanted to post notes from a remoting presentation I did for &lt;a target="_blank" href="http://www.stgutah.com"&gt;STG&lt;/a&gt; a year or so ago.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Downloads&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://interactiveasp.net/media/p/181.aspx" class="null"&gt;.NET Framework 3.5 Presentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://interactiveasp.net/media/p/180.aspx" class="null"&gt;.NET Remoting Presentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>iGen :: Open Source XSLT Code Generation Application</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/01/23/igen-open-source-xslt-code-generation-application.aspx</link><pubDate>Wed, 23 Jan 2008 21:41:00 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:10</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;I have decided to open source a project that I have been working off and on since 2003.&amp;nbsp; I have always been a big fan of code generation and felt like I knew what it takes to do it right. iGen is actually the second separate attempt.&amp;nbsp; My original attempt is named SmartDAL and is also included in the downloads below. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is iGen?&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;iGen is simply a fancy XSLT processing engine.&amp;nbsp; It works by having 2-3 main concepts. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;XML Provider - The XML provider is responsible for providing XML to the XSLT templates.&amp;nbsp; Currently it has Oracle provider and SQL Server provider.&amp;nbsp; Each of these will generate SQL that will be used in the XSLT transformation.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;XSLT Transformations - The XSLT transformations are a set of files that will transform the XML that is generated from the XML Provider.&amp;nbsp; The transformations also use a standard set of variables and accepts custom variables. &lt;/li&gt;
&lt;li&gt;File Splitter - The result of an XSLT transformation results in a single file only.&amp;nbsp; If you wish for multiple files as the output then you need to use the built-in splitter.&amp;nbsp; &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen1_5F00_2.png"&gt;&lt;img border="0" width="244" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen1_5F00_thumb.png" alt="iGen1" height="174" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This is the main screen.&amp;nbsp; The top portion is our XML Providers.&amp;nbsp; You can see that both SQL Server and Oracle are there.&amp;nbsp; This is where you configure which tables, proc's, and database relationships will be used to generate the XML data.&amp;nbsp; It may be desirable to leave out certain tables or proc's so you can choose which ones you wish to include.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen2_5F00_2.png"&gt;&lt;img border="0" width="244" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen2_5F00_thumb.png" alt="iGen2" height="102" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The options screen is used to setup project workspaces.&amp;nbsp; The idea behind this concept is that ever developer has their favorite place they like to develop code.&amp;nbsp; I like to have a D:\Projects\[Client]\[Project] structure.&amp;nbsp; Others use C:\Source.&amp;nbsp; Whatever the path it's nice to keep those different and still be able to generate code!&amp;nbsp; We will use&amp;nbsp; these workspaces in later screens. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen3_5F00_2.png"&gt;&lt;img border="0" width="244" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen3_5F00_thumb.png" alt="iGen3" height="193" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This next screen shot is of the XSLT settings dialog.&amp;nbsp; Let me go through the controls one by one. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Settings Description&lt;/strong&gt; - This is simply the text that will be displayed in the parent dialog.&amp;nbsp; Generally a short description of what you this template does is best. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;XSLT Template&lt;/strong&gt; - This is the location of the template you wish to process.&amp;nbsp; Notice that there is a drop-down box and a partial path.&amp;nbsp; This is part of the workspaces mentioned above.&amp;nbsp; Of course the path does not need to be part of the workspace provided. This should always be a valid XSLT transformation. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Provider&lt;/strong&gt; - This selects which XML Data Provider will be used for this transformation.&amp;nbsp; Because the XML that is generated does not have to follow any specific schema you are required to select a provider that is compatible with the XSLT. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filename Extension&lt;/strong&gt; - This gives the user the ability to name the file output.&amp;nbsp; If you are generating a single file then type the entire file name here.&amp;nbsp; If you are generating multiple files then put a suffix if desired and the filename extension.&amp;nbsp; In the example above the files will end with "_INSERT.sql".&amp;nbsp; The rest of the filename is generated by the XSLT transformation. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workspace / Path&lt;/strong&gt; - This is the output directory for the transformation.&amp;nbsp; Again, you can see that we are using a different workspace than defined above.&amp;nbsp; If you browse to a directory that is inside of the selected workspace path then you will only see a partial path in this box.&amp;nbsp; Otherwise you will see a full path. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parameter Window&lt;/strong&gt; - This is where you can add custom parameters for your XSLT.&amp;nbsp; These parameters can be found inside of the XSLT defined at the top of the file.&amp;nbsp; These parameters can be optional but it really depends on how the XSLT was written.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You press the generate button and away we go.&amp;nbsp; You will see what is happening and how long until it finishes.&amp;nbsp; When you are done you may choose to save your settings (after all it can be a lot of work setting these templates up).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen4_5F00_4.png"&gt;&lt;img border="0" width="244" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/iGen4_5F00_thumb_5F00_1.png" alt="iGen4" height="157" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This is an XSLT template.&amp;nbsp; You can see from the screen shot (params highlighted in yellow) that this transformation expects 5 params.&amp;nbsp; ProcPrefix, FileNameExtension, DatabaseSchema, DatabaseName, and DatabaseUserName (in no particular order).&amp;nbsp;&amp;nbsp; The FileNameExtension parameter is provided by the XSLT properties window in the "Filename Extension" fields.&amp;nbsp; The rest are custom parameters and the XSLT generation engine will not know if they are required or not.&amp;nbsp; As you can see from the screen shots above I have defined all but the "ProcPrefix".&amp;nbsp; This template is designed to make ProcPrefix optional.&amp;nbsp; It will run just fine without it.&amp;nbsp; But for those who like all of their stored procs to start with "proc_" or "sp" then they may choose to set a value for this parameter in the Parameter window in the XSLT properties dialog.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Note also the use of "#[&amp;lt;xsl:value-of select="@name" /&amp;gt;&amp;lt;xsl:value-of select="$filenameextension" /&amp;gt;]#" in the example.&amp;nbsp; The #[ and ]# are used by the file splitter.&amp;nbsp; The value inside of the tokens is used as the filename.&amp;nbsp; Ex: #[proc_USERS_INSERT.sql]# &lt;/p&gt;
&lt;p&gt;If you wish to create a custom XML Provider you simply need to implement the correct interface and place the DLL in the application directory during startup.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Known Issues:&lt;/strong&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Oracle XML provider is a little more advanced than the SQL XML provider.&amp;nbsp; The oracle provider will provide relationship information that the SQL provider does not yet. &lt;/li&gt;
&lt;li&gt;The Oracle provider is dog slow!&amp;nbsp; This is actually a performance issue with querying relationship information from an Oracle database.&amp;nbsp; For those who have to use this, I am sorry!&amp;nbsp; If it makes you feel better the XML data is cached once it is created so if you goof up on the first run the second one will be much faster. &lt;/li&gt;
&lt;li&gt;The generated classes are somewhat geared toward an Oracle Smart-Client application.&amp;nbsp; These templates and classes were all "perfected" with the Oracle client.&amp;nbsp; I much prefer to use Microsoft SQL Server 2005/2008 but sometimes you don't get to choose!&amp;nbsp; If you wish to modify the templates to work for SQL Server it probably isn't a lot of work. &lt;/li&gt;
&lt;li&gt;.tmp files are left over after generation. These are the original results from the transformation.&amp;nbsp; They can be useful for debugging. &lt;/li&gt;
&lt;li&gt;There is a "lib" directory inside of the templates directory.&amp;nbsp; This is an open source XSLT function library.&amp;nbsp; We use it to mainly make sure the case of our objects is what we need it to be.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Screen Shot of SmartDAL:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/SmartDAL_5F00_2.png"&gt;&lt;img border="0" width="244" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/SmartDAL_5F00_thumb.png" alt="SmartDAL" height="193" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;I hope you enjoy it!&amp;nbsp; Please drop me a line if you download it and if you are using it. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Downloads:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a target="_blank" href="http://interactiveasp.net/media/p/190.aspx" class="null"&gt;iGen Source&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://interactiveasp.net/media/p/191.aspx" class="null"&gt;iGen Runtime / Binary&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" href="http://interactiveasp.net/media/p/192.aspx" class="null"&gt;SmartDAL Source / Binary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks!&lt;br /&gt;Nathan Zaugg&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Credits&lt;/strong&gt;&lt;br /&gt;I wasn't alone in working on iGen.&amp;nbsp; I had a lot of help from the team that used it.&amp;nbsp; Bret Cutler, Richard Brower, and Garth Harris.&amp;nbsp; An awesome team -- I would love to work with these guys on another project!&lt;/p&gt;</description></item></channel></rss>