<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CU8HQXk5cSp7ImA9WhRUFE8.&quot;"><id>tag:blogger.com,1999:blog-32773047</id><updated>2012-01-24T09:50:30.729-07:00</updated><category term="searches" /><category term="images" /><category term="DataGridView" /><category term="OleDB" /><category term="visual basic" /><category term=".ini" /><category term="documentation" /><category term="web" /><category term="encoding" /><category term="system tray" /><category term="registry" /><category term="development" /><category term="localization" /><category term="shareware" /><category term="tool tips" /><category term="Diagnostics" /><category term="open source" /><category term="VC++" /><category term="msmq" /><category term="Formattting" /><category term="Conversion" /><category term="firefox" /><category term="notify icon" /><category term="Code Reviews" /><category term="copy" /><category term="pinvoke" /><category term="tips" /><category term="Drawing" /><category term="servlet" /><category term="email" /><category term=".net" /><category term="performance" /><category term="AntiAlias" /><category term="MD5" /><category term="marshal" /><category term="hashing" /><category term="Threading" /><category term="LINQ" /><category term="Parallel.For" /><category term="mySQL" /><category term="java" /><category term="Google Maps API" /><category term="datatable" /><category term="paste" /><category term="arrays" /><category term="binary tree" /><category term="freemasonry" /><category term="guid" /><category term="graphics" /><category term="XML" /><category term="com" /><category term="dataset" /><category term="message queues" /><category term="BackgroundWorker" /><category term="networking" /><category term="pdf" /><category term="datareader" /><category term="beta" /><category term="visual studio" /><category term="unmanaged" /><category term="Color" /><category term="DateTime" /><category term="software" /><category term="html" /><category term="SSRS" /><category term="asp.net" /><category term="remote desktop" /><category term="regular expressions" /><category term="Process" /><category term="GDI+" /><category term="Visual C++" /><category term="app.config" /><category term="Serialization" /><category term="MSMQ 3.0" /><category term="sql server reporting services" /><category term="Globalization" /><category term="mail" /><category term="dll" /><category term="javascript" /><category term="debugging" /><category term="win 32" /><category term="converter" /><category term="Paging" /><category term="DataGrid" /><category term="Threads" /><category term="DataBinding" /><category term="export" /><category term="NTidy" /><category term="Oracle" /><category term="IDE" /><category term="2d Drawing" /><category term="Strings" /><category term="Access" /><category term="batch files" /><category term="repeaters" /><category term="excel" /><category term="SMTP" /><category term="custom collections" /><category term="transactions" /><category term="windows forms" /><category term="cut" /><category term="Win32" /><category term="image" /><category term="productivity" /><category term="Visual C#" /><category term="Design Patterns" /><category term="ThreadPool" /><category term="extensions" /><category term="nesting" /><category term="fragmentation" /><category term="preparedness" /><category term="programming" /><category term="multithreading" /><category term="jsp" /><category term="balloon tool tips" /><category term="freeware" /><category term="Search" /><category term="API" /><category term="sql server" /><category term="memory leaks" /><category term="Fiscal Year" /><category term="databases" /><category term="C#" /><category term="driving directions" /><category term="zip files" /><category term="repeater" /><category term="MFC" /><category term="data structures" /><category term="data types" /><category term="sql" /><category term="TreeView" /><category term="Singleton" /><category term="ip address" /><category term="ODBC" /><category term="mozilla" /><category term="caching" /><category term="bitmap" /><title>Justins Fat Tire</title><subtitle type="html">I'm a nerd, yep I admit it freely.  I read slashdot and my job title is Software Engineer.  These are my rambling on .NET, C++, Programming, and Technology overall.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://justins-fat-tire.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>108</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/JustinsFatTire" /><feedburner:info uri="justinsfattire" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CkIBQ344fyp7ImA9WhRSGUU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-2360386008620783936</id><published>2011-11-22T09:48:00.001-07:00</published><updated>2011-11-22T09:49:12.037-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-22T09:49:12.037-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="data types" /><category scheme="http://www.blogger.com/atom/ns#" term="Conversion" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="arrays" /><title>C# convert string array to integer (or something other kind of data type) array</title><content type="html">Many times in coding you are dealing with transforming data from one type to another. &amp;nbsp;I often find myself creating integers, longs, etc from strings. &amp;nbsp;Especially in .net for some reason. &amp;nbsp;I got tired of writing tons of code to handle this. &amp;nbsp;.Net gives you a great way to convert an array from one type to another. &lt;br /&gt;
&lt;br /&gt;
Currently I would always end up writing a for loop iterating through the array and doing a manual copy. &amp;nbsp;It would look something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;string[] someStringValues;

int[] someIntValues = new int[someStringValues.Length];

for( int i = 0; i &amp;lt; someStringValues.Length; i++ )
{
&amp;nbsp; &amp;nbsp;someIntValues[i] = int.Parse( someIntValues[i] );
}&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Not horrible code, but there is a more succinct way of doing it!&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;string[] someStringValues;

int[] someIntValues = Array.ConvertAll&amp;lt;string, int&amp;gt;( someStringValues, int.Parse );&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
We have now moved all that code into 1 line. &amp;nbsp;With some more magic we can also move this into a generic templated solution and you could theoretically change any array type into another type with the appropriate converter. &amp;nbsp;This could apply not only to basic data types but complex classes with an associated converter.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-2360386008620783936?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ihlqoiy3WLa6b5ZlF6rzBL5AOYo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ihlqoiy3WLa6b5ZlF6rzBL5AOYo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ihlqoiy3WLa6b5ZlF6rzBL5AOYo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ihlqoiy3WLa6b5ZlF6rzBL5AOYo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/JrqkfN9wtrY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/2360386008620783936/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=2360386008620783936&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/2360386008620783936?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/2360386008620783936?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/JrqkfN9wtrY/c-convert-string-array-to-integer-or.html" title="C# convert string array to integer (or something other kind of data type) array" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/11/c-convert-string-array-to-integer-or.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QNQH88eip7ImA9WhRSGEU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-8540648992092729419</id><published>2011-11-18T13:45:00.001-07:00</published><updated>2011-11-21T08:29:51.172-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-21T08:29:51.172-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="caching" /><category scheme="http://www.blogger.com/atom/ns#" term="data structures" /><category scheme="http://www.blogger.com/atom/ns#" term="searches" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="binary tree" /><title>C# Simple Binary Tree</title><content type="html">Today I'm getting a bit into data structures.  Recently I've found a need to store a large amount of records (16 million) in memory as a sort of cache.  I tried using databases, etc, but it was all too slow.  I needed super fast access times, well under a millisecond to speed up a large application with many data look ups.  I tried a linked list but while the insert times were great the look ups again were too slow.  I finally settled on a binary tree.  Building the tree is slow, several minutes, but this data doesn't change and gives me super fast look up times, around .005 ms.  To achieve this I wrote a very simple binary tree class.&lt;br /&gt;
&lt;br /&gt;
It uses a node that is fit for my purposes.  To make this class even better I would implement in generics with a node class that has to implement IComparable.  This way you can make a binary tree for any type of class that can be compared.  For now I'm hard coding the key/values for my specific needs. See the rather large code block below.  I will add a zip file with the code as well.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;using System;
using System.Collections;

namespace BinaryTree
{
   
    /// &amp;lt;summary&amp;gt;
    /// A very basic Binary Search Tree. Not generalized, stores
    /// name/value pairs in the tree nodes. name is the node key.
    /// The advantage of a binary tree is its fast insert and lookup
    /// characteristics. This version does not deal with tree balancing.
    /// &amp;lt;/summary&amp;gt;
    public class TreeNode
    {
        #region Fields

        private string _name;
        
        private int[] _codes;
        
        public TreeNode Left, Right;

        #endregion

        #region Properties

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the name.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;value&amp;gt;
        /// The name.
        /// &amp;lt;/value&amp;gt;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the codes.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;value&amp;gt;
        /// The codes.
        /// &amp;lt;/value&amp;gt;
        public int[] Codes
        {
            get { return _codes; }
            set { _codes = value; }
        }
        
        #endregion

        /// &amp;lt;summary&amp;gt;
        /// Initializes a new instance of the &amp;lt;see cref="TreeNode"/&amp;gt; class.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="name"&amp;gt;The name.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="_codes"&amp;gt;The _codes.&amp;lt;/param&amp;gt;
        public TreeNode( string name, int[] codes )
        {
            _name = name;
            _codes = codes;
            Left = null;
            Right = null;
        }
    }

    /// &amp;lt;summary&amp;gt;
    /// A basic binary tree with a string, int[] node.  string is the key, int[] is the value
    /// &amp;lt;/summary&amp;gt;
    public class BinaryTree
    {
        #region Fields

        // Points to the _root of the tree
        private TreeNode _root;

        // a count of nodes in the tree, duh!
        private int _count = 0;

        #endregion

        #region Properties

        /// &amp;lt;summary&amp;gt;
        /// Returns the number of nodes in the tree
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;Number of nodes in the tree&amp;lt;/returns&amp;gt;
        public int Count
        {
            get { return _count; }
        }

        #endregion

        /// &amp;lt;summary&amp;gt;
        /// Initializes a new instance of the &amp;lt;see cref="BinaryTree"/&amp;gt; class.
        /// &amp;lt;/summary&amp;gt;
        public BinaryTree()
        {
            _root = null;
            _count = 0;
        }

        #region Public Methods

        /// &amp;lt;summary&amp;gt;
        /// Clear the binary tree.
        /// &amp;lt;/summary&amp;gt;
        public void Clear()
        {
            this.KillTree( ref _root );
            _count = 0;
        }       

        /// &amp;lt;summary&amp;gt;
        /// Find name in tree. Return a reference to the node
        /// if symbol found else return null to indicate failure.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="name"&amp;gt;Name of node to locate&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;Returns null if it fails to find the node, else returns reference to node&amp;lt;/returns&amp;gt;
        public TreeNode FindSymbol( string name )
        {
            TreeNode np = _root;

            int cmp;
            
            while( np != null )
            {
                cmp = String.CompareOrdinal( name, np.Name );

                if( cmp == 0 )   // found !
                {
                    return np;
                }

                if( cmp &amp;lt; 0 )
                {
                    np = np.Left;
                }
                else
                {
                    np = np.Right;
                }
            }
            return null;  // Return null to indicate failure to find name
        }

        /// &amp;lt;summary&amp;gt;
        /// Recursively locates an empty slot in the binary tree and inserts the node
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="node"&amp;gt;The node.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="tree"&amp;gt;The tree.&amp;lt;/param&amp;gt;
        private void Add( TreeNode node, ref TreeNode tree )
        {
            if( tree == null )
            {
                tree = node;
            }
            else
            {
                // If we find a node with the same name then it's 
                // a duplicate and we can't continue
                int comparison = String.CompareOrdinal( node.Name, tree.Name );

                if( comparison == 0 )
                {
                    throw new Exception();
                }

                if( comparison &amp;lt; 0 )
                {
                    Add( node, ref tree.Left );
                }
                else
                {
                    Add( node, ref tree.Right );
                }
            }
        }

        /// &amp;lt;summary&amp;gt;
        /// Add a symbol to the tree if it's a new one. Returns reference to the new
        /// node if a new node inserted, else returns null to indicate node already present.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="name"&amp;gt;Name of node to add to tree&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="d"&amp;gt;Value of node&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt; Returns reference to the new node is the node was inserted.
        /// If a duplicate node (same name was located then returns null&amp;lt;/returns&amp;gt;
        public TreeNode Insert( string name, int[] codes )
        {
            TreeNode node = new TreeNode( name, codes );
            try
            {
                if( _root == null )
                {
                    _root = node;
                }
                else
                {
                    Add( node, ref _root );
                }
                
                _count++;
                
                return node;

            }
            catch( Exception )
            {
                return null;
            }
        }

        // Searches for a node with name key, name. If found it returns a reference
        // to the node and to thenodes parent. Else returns null.
        private TreeNode FindParent( string name, ref TreeNode parent )
        {
            TreeNode np = _root;
            
            parent = null;
            
            int cmp;

            while( np != null )
            {
                cmp = String.Compare( name, np.Name );
                if( cmp == 0 )   // found !
                    return np;

                if( cmp &amp;lt; 0 )
                {
                    parent = np;
                    np = np.Left;
                }
                else
                {
                    parent = np;
                    np = np.Right;
                }
            }

            return null;  // Return null to indicate failure to find name

        }

        /// &amp;lt;summary&amp;gt;
        /// Find the next ordinal node starting at node startNode.
        /// Due to the structure of a binary search tree, the
        /// successor node is simply the left most node on the right branch.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="startNode"&amp;gt;Name key to use for searching&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="parent"&amp;gt;Returns the parent node if search successful&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;Returns a reference to the node if successful, else null&amp;lt;/returns&amp;gt;
        public TreeNode FindSuccessor( TreeNode startNode, ref TreeNode parent )
        {
            parent = startNode;
            
            // Look for the left-most node on the right side
            startNode = startNode.Right;
            
            while( startNode.Left != null )
            {
                parent = startNode;
                startNode = startNode.Left;
            }

            return startNode;
        }

        /// &amp;lt;summary&amp;gt;
        /// Delete a given node. This is the more complex method in the binary search
        /// class. The method considers three senarios, 1) the deleted node has no
        /// children; 2) the deleted node as one child; 3) the deleted node has two
        /// children. Case one and two are relatively simple to handle, the only
        /// unusual considerations are when the node is the _root node. Case 3) is
        /// much more complicated. It requires the location of the successor node.
        /// The node to be deleted is then replaced by the sucessor node and the
        /// successor node itself deleted. Throws an exception if the method fails
        /// to locate the node for deletion.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="key"&amp;gt;Name key of node to delete&amp;lt;/param&amp;gt;
        public void Delete( string key )
        {
            TreeNode parent = null;

            // First find the node to delete and its parent
            TreeNode nodeToDelete = FindParent( key, ref parent );
            
            if( nodeToDelete == null )
            {
                throw new Exception( "Unable to delete node: " + key.ToString() );  // can't find node, then say so 
            }

            // Three cases to consider, leaf, one child, two children

            // If it is a simple leaf then just null what the parent is pointing to
            if( ( nodeToDelete.Left == null ) &amp;amp;&amp;amp; ( nodeToDelete.Right == null ) )
            {
                if( parent == null )
                {
                    _root = null;
                    return;
                }

                // find out whether left or right is associated 
                // with the parent and null as appropriate
                if( parent.Left == nodeToDelete )
                {
                    parent.Left = null;
                }
                else
                {
                    parent.Right = null;
                }

                _count--;
                return;
            }

            // One of the children is null, in this case
            // delete the node and move child up
            if( nodeToDelete.Left == null )
            {
                // Special case if we're at the _root
                if( parent == null )
                {
                    _root = nodeToDelete.Right;
                    return;
                }

                // Identify the child and point the parent at the child
                if( parent.Left == nodeToDelete )
                {
                    parent.Right = nodeToDelete.Right;
                }
                else
                {
                    parent.Left = nodeToDelete.Right;
                }

                // Clean up the deleted node
                nodeToDelete = null; 
                _count--;
                return;

            }

            // One of the children is null, in this case
            // delete the node and move child up
            if( nodeToDelete.Right == null )
            {
                // Special case if we're at the _root            
                if( parent == null )
                {
                    _root = nodeToDelete.Left;
                    return;
                }

                // Identify the child and point the parent at the child
                if( parent.Left == nodeToDelete )
                {
                    parent.Left = nodeToDelete.Left;
                }
                else
                {
                    parent.Right = nodeToDelete.Left;
                }

                // Clean up the deleted node
                nodeToDelete = null; 
                _count--;
                return;

            }

            // Both children have nodes, therefore find the successor, 
            // replace deleted node with successor and remove successor
            // The parent argument becomes the parent of the successor
            TreeNode successor = FindSuccessor( nodeToDelete, ref parent );

            // Make a copy of the successor node
            TreeNode tmp = new TreeNode( successor.Name, successor.Codes );

            // Find out which side the successor parent is pointing to the
            // successor and remove the successor
            if( parent.Left == successor )
            {
                parent.Left = null;
            }
            else
            {
                parent.Right = null;
            }

            // Copy over the successor values to the deleted node position
            nodeToDelete.Name = tmp.Name;
            nodeToDelete.Codes = tmp.Codes;
            _count--;
        }

        /// &amp;lt;summary&amp;gt;
        /// Return the tree depicted as a simple string, useful for debugging, eg
        /// 50(40(30(20, 35), 45(44, 46)), 60)
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;Returns the tree&amp;lt;/returns&amp;gt;
        public string DrawTree()
        {
            return DrawNode( _root );
        }

        /// &amp;lt;summary&amp;gt;
        /// Returns a &amp;lt;see cref="System.String"/&amp;gt; that represents this instance.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;
        /// A &amp;lt;see cref="System.String"/&amp;gt; that represents this instance.
        /// &amp;lt;/returns&amp;gt;
        public override string ToString()
        {
            return this.DrawTree();
        }

        #endregion

        #region Private Methods

        // Recursive destruction of binary search tree, called by method clear
        // and destroy. Can be used to kill a sub-tree of a larger tree.
        // This is a hanger on from its Delphi origins, it might be dispensable
        // given the garbage collection abilities of .NET
        private void KillTree( ref TreeNode p )
        {
            if( p != null )
            {
                KillTree( ref p.Left );

                KillTree( ref p.Right );

                p = null;

            }
        }

        /// &amp;lt;summary&amp;gt;
        /// Draws the node.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="node"&amp;gt;The node.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
        private string DrawNode( TreeNode node )
        {
            if( node == null )
            {
                return "empty";
            }

            if( node.Left == null &amp;amp;&amp;amp;
                node.Right == null )
            {
                return node.Name;
            }
            if( node.Left != null &amp;amp;&amp;amp;
                node.Right == null )
            {
                return String.Format( "{0}({1}, )", node.Name, DrawNode( node.Left ) );
            }
            if( node.Right != null &amp;amp;&amp;amp;
                node.Left == null )
            {
                return String.Format( "{0}(_,{1})", node.Name, DrawNode( node.Right ) );

            }

            return String.Format( "{0}({1},{2})", node.Name, DrawNode( node.Left ), DrawNode( node.Right ) );

        }

        #endregion

    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-8540648992092729419?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YUoiblslUKy5CRn59jO22YvEzdY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YUoiblslUKy5CRn59jO22YvEzdY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YUoiblslUKy5CRn59jO22YvEzdY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YUoiblslUKy5CRn59jO22YvEzdY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/kkq4C7aAtAs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/8540648992092729419/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=8540648992092729419&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8540648992092729419?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8540648992092729419?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/kkq4C7aAtAs/c-simple-binary-tree.html" title="C# Simple Binary Tree" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/11/c-simple-binary-tree.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UHRXk4fCp7ImA9WhdUE0Q.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-8512209691634012230</id><published>2011-09-30T08:07:00.000-07:00</published><updated>2011-09-30T08:07:14.734-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-30T08:07:14.734-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Diagnostics" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Process" /><title>C# create a new process</title><content type="html">Once in a while I find myself needing to spawn a process in C#. &amp;nbsp;The .net framework has some built in functionality to do this. &amp;nbsp;It's fairly trivial to just spawn a process and let it run. &amp;nbsp;.NET however allows us many options to customize the look and feel as well as the error output of the spawned process. &amp;nbsp;The example below simply fires up notepad with a default document. &amp;nbsp;You can customize this heavily as mentioned and not show windows, etc.&lt;br /&gt;
&lt;br /&gt;
You can read all about is on &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" target="_blank"&gt;MSDN&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;// create and setup the process object
chartProcess = new Process();
chartProcess.StartInfo.FileName = "notepad.exe";

// this is all optional setup

// pass in any command line arguments if desired
chartProcess.StartInfo.Arguments = "test.txt";

//
chartProcess.StartInfo.UseShellExecute = false;

// this determines if we show the actual command or form window
chartProcess.StartInfo.CreateNoWindow = false;

// this lets us handle an event when the process we start stops
chartProcess.EnableRaisingEvents = true;
chartProcess.Exited += new EventHandler( chartProcess_Exited );

// start the process
chartProcess.Start();&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-8512209691634012230?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gBF7k-5Tsyh7q5bKzFEktBjgtV8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gBF7k-5Tsyh7q5bKzFEktBjgtV8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gBF7k-5Tsyh7q5bKzFEktBjgtV8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gBF7k-5Tsyh7q5bKzFEktBjgtV8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/cA821-Cu5so" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/8512209691634012230/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=8512209691634012230&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8512209691634012230?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8512209691634012230?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/cA821-Cu5so/c-create-new-process.html" title="C# create a new process" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/09/c-create-new-process.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04BSHw5fSp7ImA9WhdXF08.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-4046230524520656295</id><published>2011-08-30T09:31:00.001-07:00</published><updated>2011-08-30T09:32:39.225-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-30T09:32:39.225-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Parallel.For" /><category scheme="http://www.blogger.com/atom/ns#" term="multithreading" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# Parallel.For</title><content type="html">With the advent of C# 4.0 you can now write code to more efficiently use multiple core machines.  I will show a trivial example on how to do this.  This code reads through a directory and lists all the files.  Now while the example itself isn't that complicated I will show some timings and benefits on my Intel duo core 2 machine.  Running on even more cores would show an even bigger result.  This kind of computing really shines when you're dealing with large amounts of data or very intensive computations.  This test sums up 10 million random integers.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;

using System.Threading.Tasks;

static void Main( string[] args )
{
      int[] values = new int[10000000];

      Random r = new Random( DateTime.Now.Millisecond );

      double sum = 0;

      for( int i = 0; i &amp;lt; values.Length; i++ )
      {
          values[i] = r.Next( 0, 10 );
      }

      DateTime start = DateTime.Now;
      DateTime end;

      // run the test in parallel
      Parallel.For( 0, values.Length, delegate( int i )
      {
          sum += values[i];
      } );

      end = DateTime.Now;

      TimeSpan t = end - start;

      Console.WriteLine( "Parrallel For time is: " + t.TotalMilliseconds + ", sum is: " + sum );

      start = DateTime.Now;

      // run the test in sequential
      for( int i = 0; i &amp;lt; values.Length; i++ )
      {
          values[i] = r.Next( 0, 10 );
      }

      end = DateTime.Now;

      t = end - start;

      Console.WriteLine();
      Console.WriteLine( "Regular For time is: " + t.TotalMilliseconds + ", sum is: " + sum );

      Console.ReadKey();
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
The Parallel.For looks almost exactly like the regular for.  The main difference is you have to add in the delegate(int) at the end.  This is used when the compiler creates the different threads to use on the various CPUs.  A more detailed explanation can be found here:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx" target="_blank"&gt;MSDN Link&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now onto the results!&lt;br /&gt;
&lt;br /&gt;
After many runs the parallel code ran anywhere from almost twice as fast to 100 ms faster.  Now this is just a random summation of integers.  Even more computationally complex tasks should see even more benefit&lt;br /&gt;
&lt;br /&gt;
Some results:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-DHxubjML9Fk/Tl0PyV_E9SI/AAAAAAAAAQY/xiTfxdI5x94/s1600/results.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="190" target-"_blank" src="http://2.bp.blogspot.com/-DHxubjML9Fk/Tl0PyV_E9SI/AAAAAAAAAQY/xiTfxdI5x94/s320/results.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-4046230524520656295?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kBRmolnSvo347zddiC8R5kk50ko/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kBRmolnSvo347zddiC8R5kk50ko/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kBRmolnSvo347zddiC8R5kk50ko/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kBRmolnSvo347zddiC8R5kk50ko/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/HA56g7bIK7M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/4046230524520656295/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=4046230524520656295&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4046230524520656295?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4046230524520656295?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/HA56g7bIK7M/c-parallelfor.html" title="C# Parallel.For" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-DHxubjML9Fk/Tl0PyV_E9SI/AAAAAAAAAQY/xiTfxdI5x94/s72-c/results.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/08/c-parallelfor.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMHQ3s4cSp7ImA9WhdXEU8.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-4649296901565548570</id><published>2011-08-23T10:27:00.000-07:00</published><updated>2011-08-23T10:27:12.539-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-23T10:27:12.539-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MD5" /><category scheme="http://www.blogger.com/atom/ns#" term="hashing" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# create MD5 hash from a string</title><content type="html">A common task when dealing with sensitive data is to create a hash of it.  MD5 is used quite often especially when dealing with password, etc.  I will leave the discussion of collisions, etc to others and just show a function that will return an array of bytes that is the result of hashing the input string.  This function calls for an Encoding object to be passed in since you never know what encoding you will be using.  But you could easily hard code the encoding if you know that will never change.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;using System.Security.Cryptography;

/// &amp;lt;summary&amp;gt;
/// Hashes the string.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;valueToHash&amp;quot;&amp;gt;The value to hash.&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;textEncoding&amp;quot;&amp;gt;The text encoding.&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
private byte[] HashString( String valueToHash, Encoding textEncoding )
{
   byte[] result;

   using( MD5 md5 = MD5.Create() )
   {
      byte[] inputBytes = textEncoding.GetBytes( valueToHash );
      result = md5.ComputeHash( inputBytes );
   }

   return result;

}
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-4649296901565548570?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pdbkEiwbk_DGUsj-sJDshk27oDA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pdbkEiwbk_DGUsj-sJDshk27oDA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pdbkEiwbk_DGUsj-sJDshk27oDA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pdbkEiwbk_DGUsj-sJDshk27oDA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/Gg3Gjzkcd3E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/4649296901565548570/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=4649296901565548570&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4649296901565548570?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4649296901565548570?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/Gg3Gjzkcd3E/c-create-md5-hash-from-string.html" title="C# create MD5 hash from a string" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/08/c-create-md5-hash-from-string.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AGQXY7eCp7ImA9WhdQFkU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-1642789392763978731</id><published>2011-08-18T08:35:00.000-07:00</published><updated>2011-08-18T08:35:20.800-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-18T08:35:20.800-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="DateTime" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# get the number of days in a month</title><content type="html">Ok this isn't the longest blog post, but it contains a handy little code snippet.  Sometimes you find yourself needing to know the number of days in any given month.  The code below will get you the last day of the month.  I'm using the current month but you could use any month.   You just need to know the month and year you're looking for.  The magic lies in the DateTime.DaysInMonth method.  You pass in the year and month and it returns the number of days in that month.  The code below is pretty self explanatory.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;static void Main( string[] args )
{
   DateTime now = DateTime.Now;

   int daysInMonth = DateTime.DaysInMonth( now.Year, now.Month );

   String dateFormat = String.Format( "Last day of the month is - {0}/{1}/{2}", now.Month, daysInMonth, now.Year);

   Console.WriteLine( dateFormat);

   Console.ReadKey();

}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
And a brief picture showing the output, obviously I ran this is October 2011.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-z4WMRwcc9O0/Tk0wguCUZ8I/AAAAAAAAAPU/BXhPGgES7MU/s1600/last_day_of_month.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="190" src="http://3.bp.blogspot.com/-z4WMRwcc9O0/Tk0wguCUZ8I/AAAAAAAAAPU/BXhPGgES7MU/s320/last_day_of_month.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-1642789392763978731?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Yp2Q9Y-6gC3_gTQlQx2Sq70oArY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Yp2Q9Y-6gC3_gTQlQx2Sq70oArY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Yp2Q9Y-6gC3_gTQlQx2Sq70oArY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Yp2Q9Y-6gC3_gTQlQx2Sq70oArY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/wbKTY-NbUns" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/1642789392763978731/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=1642789392763978731&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/1642789392763978731?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/1642789392763978731?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/wbKTY-NbUns/c-get-number-of-days-in-month.html" title="C# get the number of days in a month" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-z4WMRwcc9O0/Tk0wguCUZ8I/AAAAAAAAAPU/BXhPGgES7MU/s72-c/last_day_of_month.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/08/c-get-number-of-days-in-month.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0YDSH0zfSp7ImA9WhdQFE8.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-1979470158293054503</id><published>2011-08-15T10:25:00.003-07:00</published><updated>2011-08-15T10:26:19.385-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-15T10:26:19.385-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ip address" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="networking" /><title>C# Get the ip address of a host name</title><content type="html">Often times you want to find the ip address of a host name.  This function will do this for you.  It returns the first address.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;using System.Net;

public string GetIPAddress(string sHostName)
{
   IPHostEntry ipEntry = Dns.GetHostByName(sHostName);
   IPAddress [] addr = ipEntry.AddressList;
   string sIPAddress = addr[0].ToString();

   return sIPAddress;

}
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-1979470158293054503?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5CaTulon1IOL1ovS4FHqy3ROgfo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5CaTulon1IOL1ovS4FHqy3ROgfo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5CaTulon1IOL1ovS4FHqy3ROgfo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5CaTulon1IOL1ovS4FHqy3ROgfo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/tVp1y0kuA-g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/1979470158293054503/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=1979470158293054503&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/1979470158293054503?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/1979470158293054503?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/tVp1y0kuA-g/c-get-ip-address-of-host-name.html" title="C# Get the ip address of a host name" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/08/c-get-ip-address-of-host-name.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EHRno9fyp7ImA9WhdTF0k.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-539918641622992128</id><published>2011-07-15T10:01:00.001-07:00</published><updated>2011-07-15T10:07:17.467-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-15T10:07:17.467-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Globalization" /><category scheme="http://www.blogger.com/atom/ns#" term="DateTime" /><category scheme="http://www.blogger.com/atom/ns#" term="localization" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# format date times for different locals (localization and globalization), DateTimeFormatInfo</title><content type="html">Working on a project recently I found we were presenting date/time data to a variety of users in various countries.  Each country uses it's own date/time formatting.  Here in the US it's often MM/dd/yyyy, however in Europe it's often dd/MM/yyyy and in Asia they don't even have the slashes they use special characters that designate year, month, and day.  At first we were going to come up with localized versions of all the possible date/time combinations you can display (June 6th, 1977, 6/25/77, etc) but Microsoft has an even better solution already in place.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;static void Main( string[] args )
{
         DateTime dt = DateTime.Now;

         // let's create some different date times for different cultures

         // JAPANESE
         CultureInfo culture = new CultureInfo(&amp;quot;ja-JP&amp;quot;);
         DateTimeFormatInfo formatInfo = culture.DateTimeFormat;
         String time = dt.ToString( formatInfo.FullDateTimePattern, culture );
         MessageBox.Show( time );

         // ENGLISH
         culture = new CultureInfo( &amp;quot;en-US&amp;quot; );
         formatInfo = culture.DateTimeFormat;
         time = dt.ToString( formatInfo.FullDateTimePattern, culture );
         MessageBox.Show( time );

         // SIMPLIFIED CHINESE
         culture = new CultureInfo( &amp;quot;zh-CN&amp;quot; );
         formatInfo = culture.DateTimeFormat;
         time = dt.ToString( formatInfo.FullDateTimePattern, culture );
         MessageBox.Show( time );

         // FRENCH
         culture = new CultureInfo( &amp;quot;fr-FR&amp;quot; );
         formatInfo = culture.DateTimeFormat;
         time = dt.ToString( formatInfo.FullDateTimePattern, culture );
         MessageBox.Show( time );

         Console.ReadKey();

}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Looking at the code, we take the current date time and use the format string from the DateTimeFormatInfo to convert the current date time into the date time of the specified culture.  In this example I'm using the FullDateTimePattern, but the DateTimeFormatInfo class has a many different formats you can use.  &lt;br /&gt;
&lt;br /&gt;
You can read about all the different formats at &lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx" target="_blank"&gt;MSDN&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--MBW-sl_AJ8/TiBzlphhZAI/AAAAAAAAAJU/M9tvuSsJ0rk/s1600/cultures.PNG" imageanchor="1" style=""&gt;&lt;img border="0" height="400" width="171" src="http://2.bp.blogspot.com/--MBW-sl_AJ8/TiBzlphhZAI/AAAAAAAAAJU/M9tvuSsJ0rk/s400/cultures.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
I hope this example helps you easily get date/times formatted into the various cultures.  I know I've found it quite useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-539918641622992128?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9zc0SqSYeZCPvpypvl71ugMzlww/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9zc0SqSYeZCPvpypvl71ugMzlww/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9zc0SqSYeZCPvpypvl71ugMzlww/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9zc0SqSYeZCPvpypvl71ugMzlww/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/MKin316d5iM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/539918641622992128/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=539918641622992128&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/539918641622992128?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/539918641622992128?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/MKin316d5iM/c-format-date-times-for-different.html" title="C# format date times for different locals (localization and globalization), DateTimeFormatInfo" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/--MBW-sl_AJ8/TiBzlphhZAI/AAAAAAAAAJU/M9tvuSsJ0rk/s72-c/cultures.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/07/c-format-date-times-for-different.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04CSH45fip7ImA9WhZbF0g.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-4410589972155069822</id><published>2011-06-22T09:21:00.001-07:00</published><updated>2011-06-22T09:26:09.026-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-22T09:26:09.026-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="marshal" /><category scheme="http://www.blogger.com/atom/ns#" term="unmanaged" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="pinvoke" /><title>Using more complicated PInvoke calls</title><content type="html">In my last blog post I covered using a very basic PInvoke call to an unmanaged dll that returned an integer.  For basic data types int, char, double, float, etc you don't need to do any manual marshaling.  However, especially with the Win32 API you will find yourself needing to use more complicated types.  Even getting a string back from an unmanaged dll takes more work, and then we have classes, structs, arrays, etc we need to deal with.&lt;br /&gt;
&lt;br /&gt;
Let's look at some unmanaged dll signatures&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;extern &amp;quot;C&amp;quot;
{
   struct
   {
      char* NAME,
      char* ADDRESS,
      int age
   } PERSON;

   void FillByteArray( unsigned char* byteArray, int arrayLength );

   const char* GetLastErrorMessage();

   void FillAStruct( PERSON* pPerson );

}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Now here we have three functions; one fills a byte array, one returns a string, and another modifies a struct we've defined.  Nothing complicated on the C++ side but we need to be careful when we start using pinvoke to call these functions.  Let's look at some C# code that we can use to call these functions.&lt;br /&gt;
&lt;br /&gt;
First let's fill that byte array with some data.  Now I know you won't know the size of the array every time but after working with pinvoke arrays it's better if you can pass in the size of the array, it makes working with them much easier.&lt;br /&gt;
&lt;br /&gt;
Let's start with the byte array&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;[DllImport(MyDll.dll)]
public static extern void FillByteArray( byte[] array, int arrayLength );&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
C/C++ treats arrays as pointers, so we're going to let the framework handle the memory management for us and just pass in an array with the array length.  We can let the .net framework handle the memory mapping from our call to the actual dll memory use.  The above function works very well for basic data types, but we often find ourselves needing to use more complicated types like strings and structs when dealing with unmanaged code.  I will cover those items next.&lt;br /&gt;
&lt;br /&gt;
Let's look at the function&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;const char* GetLastErrorMessage();&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
You might think &lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;[DllImport(MyDll.dll)]
public static extern string GetLastErrorMessage();&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Would be enough.  Sadly dealing with strings gets complicated when making pinvoke calls.  I have found when dealing with any strings in pinvoke calls it's simply better to use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.intptr(v=vs.71).aspx" _target="_blank"&gt;IntPtr&lt;/a&gt; class with the &lt;a href="http://msdn.microsoft.com/en-us/library/7b620dhe.aspx" target="_blank"&gt;Marshal&lt;/a&gt; static helper functions.  Let's look at some code below.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&lt;span style="color:green;"&gt;// declare the function&lt;/span&gt;
[DllImport(MyDll.dll)]
public static extern IntPtr GetLastErrorMessage();

&lt;span style="color:green;"&gt;// call the function and get back and IntPtr&lt;/span&gt;
IntPtr ptrResult = GetLastErrorMessage();

&lt;span style="color:green;"&gt;// always check we have a valid pointer before calling the marshal code
// now we need to convert this pointer back to a string&lt;/span&gt;
if( ptrResult != IntPtr.Zero )
{
&lt;span style="color:green;"&gt;   // this will convert the pointerto an ansi string
   // there are other methods, but we always use ansi strings
   // look at the marshal documentation for the other string options&lt;/span&gt;
   String errorMessage = Marshal.PtrToStringAnsi(ptrResult);
}

Console.WriteLine( errorMessage );&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Now let's take a look at the final example.  Passing in a struct that the unmanaged code can read/modify etc.  This one takes a bit more work but is very handy, especially since many of the Win32 APIs take their own struct definitions as input parameters.  Now you will need to know the structure of the struct you plan to use.  This isn't an issue usually when you have access to the source code or documentation but it needs to be noted.&lt;br /&gt;
&lt;br /&gt;
First we need to have a struct that matches the struct in the unmanaged side.  You can use a class if desired but I have found it easier to make a struct that matches exactly.  I often find myself using an internal private struct to make the call and that using a helper class that converts the struct to a standard C# class.&lt;br /&gt;
&lt;br /&gt;
So let's look at some C# code.  First we need to create a struct that matches that unmanaged side struct.  From above wherever we have string, use an IntPtr.  For the int we can match the basic data type.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public struct Person
{
   public IntPtr name;
   public IntPtr address;
   public int age;
}&lt;/pre&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-4410589972155069822?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MqetHuFged15R8FuLdeUmbAl2qM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MqetHuFged15R8FuLdeUmbAl2qM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MqetHuFged15R8FuLdeUmbAl2qM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MqetHuFged15R8FuLdeUmbAl2qM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/u6RAV3iDJvM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/4410589972155069822/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=4410589972155069822&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4410589972155069822?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4410589972155069822?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/u6RAV3iDJvM/using-more-complicated-pinvoke-calls.html" title="Using more complicated PInvoke calls" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/06/using-more-complicated-pinvoke-calls.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04BSHYyfSp7ImA9WhZWFUo.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-5039743344404613015</id><published>2011-05-16T11:52:00.000-07:00</published><updated>2011-05-16T11:52:39.895-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-16T11:52:39.895-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="unmanaged" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="pinvoke" /><title>C# using PInvoke to call an unmanaged DLL</title><content type="html">Recently I've found myself having to do some pinvoking with .net.  Microsoft offers an excellent primer on the subject.&lt;br /&gt;
&lt;br /&gt;
http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx&lt;br /&gt;
&lt;br /&gt;
For it's many great benefits the .net framework doesn't do everything.  You will find yourself having to invoke a win32 API function call at some point in your career.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I'm going to offer some quick and dirty samples on getting data back and forth using the platform invoke.  First you cannot invoke any classes using pinvoke.  You get 1 function call at a time.  If you want classes you will need to write a custom CLI/C++ wrapper.  But that goes beyond the scope of this post.&lt;br /&gt;
&lt;br /&gt;
First let's look at the unmanaged\win32 side of things.  Let's say you have a dll called MyDll.dll.  In this dll you have a bunch of functions.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;// this lets use export functions from the dll
#define  DllExport  __declspec( dllexport ) 

// first we use extern &amp;quot;C&amp;quot; so we don't get name mangling in the dll
// .net doesn't play well with C++ function names so we must use the extern
extern &amp;quot;C&amp;quot;
{    
    // we're going to export this function using the __stdcall calling convention
    // .net uses __stdcall by default, so we want to ensure we have it here
    DllExport int __stdcall Add( int A, int B )
    {
        return A + B;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
So a quick re-cap, we're going to export a single function called Add, using the __stdcall calling convention.  Now let's look at using this function in a .net application.  The trick is to use the DllImport attribute, located in the System.Runtime.InteropServices namespace.  Below is an example of using the DllImport to use our Add method.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;[DllImport( &amp;quot;MyDll.dll&amp;quot; )]
public static extern int Add( int A, int B );

// call our add method!
int result = Add( 1, 2 );

&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
.Net is actually very good at matching the basic data types (int, long, bool, etc).  Strings, delegates, classes, structs, etc require more work to function correctly.  For those we will start getting into more manual marshaling of data.  I have found for most basic dll calls letting the framework handle the marshaling saves a lot of time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-5039743344404613015?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lsCDUKXOSmsTik38pdLFVzjnaTA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lsCDUKXOSmsTik38pdLFVzjnaTA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lsCDUKXOSmsTik38pdLFVzjnaTA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lsCDUKXOSmsTik38pdLFVzjnaTA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/4z4gPgKPEHE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/5039743344404613015/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=5039743344404613015&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5039743344404613015?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5039743344404613015?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/4z4gPgKPEHE/c-using-pinvoke-to-call-unmanaged-dll.html" title="C# using PInvoke to call an unmanaged DLL" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/05/c-using-pinvoke-to-call-unmanaged-dll.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MDQnczeCp7ImA9WhZWEEk.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-5040276427598742817</id><published>2011-05-10T09:37:00.000-07:00</published><updated>2011-05-10T09:37:53.980-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-10T09:37:53.980-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term="Threads" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# More on threading, killing a thread, waiting for, or how to do a Thread.Join</title><content type="html">In my last post I used a ThreadPool to do some work.  ThreadPools are great and I use them a lot.  However many times I find myself really only needing 1 thread and I need to have some control over it.  I may need to wait for it to finish, or more importantly I need to be able to control when it dies or completes its task.  For this case I always use Thread.Join&lt;br /&gt;
&lt;br /&gt;
As usual please peruse the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.join.aspx" target="_blank"&gt;MSDN documentation&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Thread.Join waits for the thread to complete before proceeding with any other operations.  So simply creating a thread then calling Thread.Join can be useful in some UI operations I tend to not call Join until I'm ready to kill the thread entirely.  The MSDN link above goes over the great details.&lt;br /&gt;
&lt;br /&gt;
Now let's go over some quick code.  This example creates a thread then waits for the user to press a key and terminates the thread.&lt;br /&gt;
&lt;br /&gt;
Let's look at the main console code&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ThreadExample
{
    class Program
    {
        static void Main( string[] args )
        {
            // create a class for use in threading
            ThreadWorker worker = new ThreadWorker();
            worker.IsAlive = true;

            // let's create a thread to do some work
            // pass the worker classes DoWork method as the method to do the work in
            Thread t = new Thread( new ThreadStart( worker.DoWork ) );

            // start the thread
            t.Start();

            // let the thread run while we wait for a key press
            Console.ReadKey();

            // send the kill signal
            // and do the join to wait for processing to end
            worker.IsAlive = false;
            t.Join();

            Console.WriteLine( &amp;quot;Press any key to terminate...&amp;quot; );
            Console.ReadKey();

        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
It starts a thread, sets it to be alive and then waits for a key press. Once they key is pressed it sets IsAlive to false and waits for the thread to terminate.  Now let's look at the thread code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ThreadExample
{
    public class ThreadWorker
    {
        private volatile bool _isAlive = false;

        public bool IsAlive
        {
            get { return _isAlive; }
            set { _isAlive = value; }
        }

        public ThreadWorker()
        {
        }

        public void DoWork()
        {
            int i = 0;

            while( _isAlive )
            {
                Console.WriteLine( &amp;quot;Current iteration is {0}&amp;quot;, i++ );
                Thread.Sleep( 100 );
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
This thread takes a volatile bool (used for thread safety, not the best method, but it works for this example) and simply writes to the console while it's in the alive state.&lt;br /&gt;
&lt;br /&gt;
Here is the output from the program&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-EAwwwnF3oeY/TclpM3PVYSI/AAAAAAAAAIA/9z5F0JGCNvA/s1600/threading.PNG" imageanchor="1" style=""&gt;&lt;img border="0" height="238" width="400" src="http://4.bp.blogspot.com/-EAwwwnF3oeY/TclpM3PVYSI/AAAAAAAAAIA/9z5F0JGCNvA/s400/threading.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
As you can see the thread runs until a key press is made and it terminates.  This is a very basic example on how to create a thread and send it a kill signal.  I used to be a big background worker user, but I find this method much quicker and easier to setup and use.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-5040276427598742817?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OdwOyJyxNZlJm0pdcChKRa73jOc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OdwOyJyxNZlJm0pdcChKRa73jOc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OdwOyJyxNZlJm0pdcChKRa73jOc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OdwOyJyxNZlJm0pdcChKRa73jOc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/Mc0mlcgNUhQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/5040276427598742817/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=5040276427598742817&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5040276427598742817?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5040276427598742817?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/Mc0mlcgNUhQ/c-more-on-threading-killing-thread.html" title="C# More on threading, killing a thread, waiting for, or how to do a Thread.Join" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-EAwwwnF3oeY/TclpM3PVYSI/AAAAAAAAAIA/9z5F0JGCNvA/s72-c/threading.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/05/c-more-on-threading-killing-thread.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkECQH89eyp7ImA9WhZQEk4.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-3624319254229979280</id><published>2011-04-19T09:31:00.000-07:00</published><updated>2011-04-19T09:31:01.163-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-19T09:31:01.163-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ThreadPool" /><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Threading in C# using the ThreadPool</title><content type="html">Threading is one of those topics that creates a lot of discussion in programming.  Threading in C# is quite easy.  However using it correctly, especially when you start doing data access or sharing information across threads it becomes difficult to keep everything in sync.  For this example I'm going to focus on creating some basic threads that run and do some basic output to show we have concurrent threads running.  You could create a thread and start it, then join, etc.  I prefer to let .net handle the thread creation and use the ThreadPool to do all the thread management for us.&lt;br /&gt;
&lt;br /&gt;
You can read more about the ThreadPool here:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx" target="_blank"&gt;MSDN Site&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I normally don't post entire files but this post is a bit different.  Let's start with the program that is running the threads.  We create 20 threads and pass them an index and a ManualResetEvent.  This is so we know which thread is exiting and we need to keep track of when the thread is done processing.  If we don't care about when the thread terminates there is no need for the manual reset event.  It's simply there for the WaitHandle.WaitAll call.  The code is below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ThreadPoolManager
{
    class Program
    {
        static void Main( string[] args )
        {
            int count = 20;

            ManualResetEvent[] doneEvents = new ManualResetEvent[count];

            for( int i = 0; i &amp;lt; count; i++ )
            {
                // create a ManaulResetEvent that is set to fals
                // this means it's not done procvess
                doneEvents[i] = new ManualResetEvent( false );

                // create an instance of our threading helper class
                // passing int he index and manual reset event
                ThreadCounter threadCounter = new ThreadCounter( i, doneEvents[i] );

                // queue the worker items, they will run and terminate automatically
                ThreadPool.QueueUserWorkItem( new WaitCallback( threadCounter.DoWork ) );


            }

            // wait for all the threads to finish
            WaitHandle.WaitAll( doneEvents );

            // do some output and let the user press the enter key
            Console.WriteLine();
            Console.WriteLine( "Done processing...Pmsress any key to terminate" );

            Console.ReadKey();

        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
This code uses a custom class called ThreadCounter.  ThreadCounter simply takes and index and a manual reset event.  In the code above we tell the ThreadPool to use the ThreadCounter's DoWork method.  To use this we need to pass an object into the callback method that could potentially have state information in it that is useful to the thread.  We're not doing anything with that information.  All this basic example does is sleep for a random time between .5 and 5 seconds.  See the code below.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ThreadPoolManager
{
    /// &amp;lt;summary&amp;gt;
    /// A basic class used to hold a thread counter index
    /// &amp;lt;/summary&amp;gt;
    public class ThreadCounter
    {
        #region Fields

        private int _index;

        private ManualResetEvent _doneEvent;

        #endregion

        #region Properties

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the index.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;value&amp;gt;The index.&amp;lt;/value&amp;gt;
        public int Index
        {
            get { return _index; }
            set { _index = value; }
        }

        #endregion

        /// &amp;lt;summary&amp;gt;
        /// Initializes a new instance of the &amp;lt;see cref="ThreadCounter"/&amp;gt; class.
        /// &amp;lt;/summary&amp;gt;
        public ThreadCounter()
        {
        }

        /// &amp;lt;summary&amp;gt;
        /// Initializes a new instance of the &amp;lt;see cref="ThreadCounter"/&amp;gt; class.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="index"&amp;gt;The index.&amp;lt;/param&amp;gt;
        public ThreadCounter( int index, ManualResetEvent doneEvent )
        {
            _index = index;
            _doneEvent = doneEvent;
        }

        /// &amp;lt;summary&amp;gt;
        /// Does the work.
        /// &amp;lt;/summary&amp;gt;
        public void DoWork( object stateInfo )
        {
            // we want this thread to sleep for some random amount of time
            Random r = new Random();
            int sleepTime = r.Next( 500, 5000 );
            Thread.Sleep( sleepTime );

            Console.WriteLine( this.ToString() );

            // set our done event so that any wait handles know we're done
            _doneEvent.Set();

        }

        /// &amp;lt;summary&amp;gt;
        /// Returns a &amp;lt;see cref="System.String"/&amp;gt; that represents this instance.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;
        /// A &amp;lt;see cref="System.String"/&amp;gt; that represents this instance.
        /// &amp;lt;/returns&amp;gt;
        public override string ToString()
        {
            return String.Format( "This is thread {0} exiting.", _index );
        }

    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Below are the results from the program being run.  As you can see the threads sleep for random times and are finishing in a random order.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-E_Ct9v9yTuk/Ta23NYzFWHI/AAAAAAAAAH4/feg52tYwGvg/s1600/threading.PNG" imageanchor="1"&gt;&lt;img border="0" height="238" src="http://2.bp.blogspot.com/-E_Ct9v9yTuk/Ta23NYzFWHI/AAAAAAAAAH4/feg52tYwGvg/s400/threading.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
I've attached the entire project in a zip file below for anyone to download.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://home.comcast.net/~jlechem/ThreadPoolManager.zip" target="_blank"&gt;Thread Pool Manager Zip File&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-3624319254229979280?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5joiWu_qWFQL0aEuEL1FW_HqmeU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5joiWu_qWFQL0aEuEL1FW_HqmeU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5joiWu_qWFQL0aEuEL1FW_HqmeU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5joiWu_qWFQL0aEuEL1FW_HqmeU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/i0b6eoBGr_s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/3624319254229979280/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=3624319254229979280&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/3624319254229979280?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/3624319254229979280?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/i0b6eoBGr_s/threading-in-c-using-threadpool.html" title="Threading in C# using the ThreadPool" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-E_Ct9v9yTuk/Ta23NYzFWHI/AAAAAAAAAH4/feg52tYwGvg/s72-c/threading.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/04/threading-in-c-using-threadpool.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04BQng-eyp7ImA9Wx9bFU0.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-1394136950433534331</id><published>2011-02-23T15:59:00.000-07:00</published><updated>2011-02-23T15:59:13.653-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-23T15:59:13.653-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# Lock, Sleep, and Hibernate Windows</title><content type="html">This could be a very uncommon occurrence but you might find a need in C# to set the computers sleep or hibernate state.  You might even need to lock the entire pc.  .NET has two of the needs built in, the third you will need to do some pinvoking.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;
// set the computer to hibernate
bool retVal = Application.SetSuspendState( PowerState.Hibernate, false, false );

if( retVal == false )
{
   MessageBox.Show( &amp;quot;Unable to hibernate the system.&amp;quot; );
}


// set the computer to suspended
bool retVal = Application.SetSuspendState( PowerState.Suspend, false, false );

if( retVal == false )
{
   MessageBox.Show( &amp;quot;Unable to suspend the system.&amp;quot; );
}

// lock the workstation
// we need to import from user32.dll, the LockWorkStation function
[DllImport(&amp;quot;user32.dll&amp;quot;, SetLastError = true)]  
static extern bool LockWorkStation();  

bool result = LockWorkStation();  
  
if (result == false)  
{  
   // TODO: an error occured
}  

&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
The Application.SetSuspendState is the big call here.  Here is the MSDN link:&lt;br /&gt;
&lt;br /&gt;
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setsuspendstate.aspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-1394136950433534331?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ThSxbCU6wVEwSba4rpQByW2OuL0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ThSxbCU6wVEwSba4rpQByW2OuL0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ThSxbCU6wVEwSba4rpQByW2OuL0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ThSxbCU6wVEwSba4rpQByW2OuL0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/x51E3sbSfUA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/1394136950433534331/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=1394136950433534331&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/1394136950433534331?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/1394136950433534331?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/x51E3sbSfUA/c-lock-sleep-and-hibernate-windows.html" title="C# Lock, Sleep, and Hibernate Windows" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/02/c-lock-sleep-and-hibernate-windows.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEAERXs5fyp7ImA9Wx9bEEs.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-8117676488969140650</id><published>2011-02-17T10:12:00.001-07:00</published><updated>2011-02-18T15:05:04.527-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-18T15:05:04.527-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ip address" /><category scheme="http://www.blogger.com/atom/ns#" term="MFC" /><category scheme="http://www.blogger.com/atom/ns#" term="VC++" /><category scheme="http://www.blogger.com/atom/ns#" term="networking" /><title>MFC get your external ip address</title><content type="html">I recently wrote a program in MFC that would monitor your ip address.&amp;nbsp; This was  great but I soon realized if your behind a NAT of some kind you get your  internal ip address.&amp;nbsp; I soon realized a need to know my external ip address.&amp;nbsp;  There is no built in functionality to do this in windows so you have to ping an  outside server or website that will tell you what your ip address is.&amp;nbsp; There are  several ways to do this sockets, an http request, or urlmon.&amp;nbsp; Many people say  sockets is the best since you can use any version of windows and create&amp;nbsp;a  socket.&amp;nbsp; The issue is the socket code is extremely long and complicated.&amp;nbsp; I only  need to support windows 2000 and above so I decided using the urlmon way was  much simpler and faster.&amp;nbsp; Here is some code in MFC to hit an outside website  which returns your IP address in file that you then parse for the data.&lt;br /&gt;
&lt;br /&gt;
This is in a class with a CString member variable called&amp;nbsp;m_strExternalIp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;
m_strExternalIp = _T( &amp;quot;Unavailable&amp;quot; );

try
{    
   &lt;span style="color:green;"&gt; /*

        to make the UrlDownloadToFile call you need the following defined

        #include &amp;lt;urlmon.h&amp;gt;

        #pragma comment(lib, &amp;quot;urlmon.lib&amp;quot;)

        */&lt;/span&gt;

     &lt;span style="color:green;"&gt;// holds the url to check and the name of the file to write the data to&lt;/span&gt;
    TCHAR url[47] = _T(&amp;quot;http://checkip.dyndns.org/Current IP Check.htm&amp;quot;);
    TCHAR file[7] = _T(&amp;quot;ip.txt&amp;quot;);

     &lt;span style="color:green;"&gt;// here is the urlmon.dll method call, see note above&lt;/span&gt;
    if( URLDownloadToFile( 0, url, file, 0, 0) == S_OK )
    {
        CStdioFile file;

         &lt;span style="color:green;"&gt;// open the file for reading&lt;/span&gt;
        if( file.Open( _T(&amp;quot;ip.txt&amp;quot;), CFile::modeRead &amp;#124; CFile::modeNoTruncate ) )
        {
            file.ReadString( m_strExternalIp );
 
             &lt;span style="color:green;"&gt;// file if successful is in format
            // &amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Current IPCheck&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;Current IP Address: 174.52.71.72&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
            if( m_strExternalIp.GetLength() &amp;gt; 110 )
            {
                m_strExternalIp = _T( &amp;quot;Unable to access IP check site&amp;quot; );
            }
            else
            {
                m_strExternalIp = m_strExternalIp.Mid( m_strExternalIp.Find( _T(&amp;quot;: &amp;quot;) ) + 1, m_strExternalIp.GetLength() - m_strExternalIp.Find( _T(&amp;quot;&amp;lt;/body&amp;gt;&amp;quot;) ) - 1 );
             }

             &lt;span style="color:green;"&gt;// always close the file&lt;/span&gt;
            file.Close();

        }
    }
    else
    {
        m_strExternalIp = _T( &amp;quot;Unable to access IP check site&amp;quot; );
    }
  }
 catch( CException* ex )
 {
     &lt;span style="color:green;"&gt;// write any errors to a log file&lt;/span&gt;
    TCHAR   szCause[255];
    CString strFormatted;

    ex-&amp;gt;GetErrorMessage(szCause, 255);

    strFormatted = _T(&amp;quot;The following error occurred: &amp;quot;);
    strFormatted += szCause;

    CStdioFile file(_T(&amp;quot;error_log.txt&amp;quot;), CFile::modeWrite &amp;#124; CFile::modeNoTruncate );

    if( file )
    {
        file.WriteString( strFormatted );
    }

    file.Close();

    delete ex;

}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Read more about the urlmon stuff on MSDN&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-8117676488969140650?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d4vi15dh6gof6FiU_jHtpj-Z2Tc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d4vi15dh6gof6FiU_jHtpj-Z2Tc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d4vi15dh6gof6FiU_jHtpj-Z2Tc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d4vi15dh6gof6FiU_jHtpj-Z2Tc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/wGlGTw1keEM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/8117676488969140650/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=8117676488969140650&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8117676488969140650?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8117676488969140650?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/wGlGTw1keEM/mfc-get-your-external-ip-address.html" title="MFC get your external ip address" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/02/mfc-get-your-external-ip-address.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUFSHg5fSp7ImA9Wx9bEEk.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-7275555324060335559</id><published>2011-02-14T12:09:00.002-07:00</published><updated>2011-02-18T08:50:19.625-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-18T08:50:19.625-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="javascript" /><category scheme="http://www.blogger.com/atom/ns#" term="driving directions" /><category scheme="http://www.blogger.com/atom/ns#" term="Google Maps API" /><category scheme="http://www.blogger.com/atom/ns#" term="html" /><title>Using google maps API for driving directions</title><content type="html">This is a bit different than my usual blog postings but I think it will help a lot of people. &amp;nbsp;I recently have found a need to generate a Google Map with driving directions based on some customer input. &amp;nbsp;After a few hours looking over some javascript API's I found a very simple solution on Google.com itself. &amp;nbsp;There are a few different versions of the API and this solution uses version 2.0. &amp;nbsp;I believe the current version is 3.0. &amp;nbsp;I have no clue when if ever they will deprecate the API but it could happen. &amp;nbsp;They also state if you call this service more than 2,500 times a day you will get banned so don't abuse the service. &amp;nbsp;My use is light at best maybe once or twice a day. &amp;nbsp;I have found it to be fairly fast and light weight.&lt;br /&gt;
&lt;br /&gt;
UPDATE!!&lt;br /&gt;
&lt;br /&gt;
Looks like Google wants you to have a key to use the maps.  You will need to signup for a key here:&lt;br /&gt;
&lt;br /&gt;
http://code.google.com/apis/maps/signup.html&lt;br /&gt;
&lt;br /&gt;
It takes a few seconds and you will need to add the key to the query string used.&lt;br /&gt;
&lt;br /&gt;
Now onto the code!&lt;br /&gt;
&lt;br /&gt;
It just takes some HTML and&amp;nbsp;JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml" &amp;nbsp;xmlns:v="urn:schemas-microsoft-com:vml"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;head&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;title&amp;gt;Google Maps JavaScript API Example: Simple Directions&amp;lt;/title&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;script src="http://maps.google.com/maps?file=api&amp;amp;v=2.x&amp;amp;key=YOUR_KEY_HERE"
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;script type="text/javascript"&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;function gup( name )
&amp;nbsp;&amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var regexS = "[\\?&amp;amp;]"+name+"=([^&amp;amp;#]*)";
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var regex = new RegExp( regexS );
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var results = regex.exec( window.location.href );
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if( results == null )
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return "";
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return results[1];
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; &amp;nbsp;// Create a directions object and register a map and DIV to hold the
&amp;nbsp;&amp;nbsp; &amp;nbsp;// resulting computed directions

&amp;nbsp;&amp;nbsp; &amp;nbsp;var map;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var directionsPanel;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var directions;

&amp;nbsp;&amp;nbsp; &amp;nbsp;function initialize() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;map = new GMap2(document.getElementById("map_canvas"));
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;directionsPanel = document.getElementById("route");
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;directions = new GDirections(map, directionsPanel);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;directions.load('from: gup('origin') to: ' + gup('destination') + "'");
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; &amp;nbsp;function printMap() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var button = document.getElementById("buttonPrint");
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;button.style.visibility ='hidden'; //hide
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;button.style.visibility ='visible'; // show &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;/head&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;lt;body onload="initialize()"&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;input type="button" value="print" id="buttonPrint" onclick="printMap();" /&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;div id="route" style="width: 480px; height:320px; border; 1px solid black;" /&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;br/&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;div id="map_canvas" style="width: 480px%; height: 480px; border: 1px solid black;" /&amp;gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;br/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&amp;nbsp;&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Let's look at the HTML, we have 2 divs. &amp;nbsp;One for the map and one for the instructions. &amp;nbsp;I have them arranged &amp;nbsp;in vertical order so they can be printed. &amp;nbsp;You can lay them out however you want.&lt;br /&gt;
&lt;br /&gt;
Now there are three JavaScript&amp;nbsp;functions&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;"&gt;initialize, gup, and printMap.  Initialize is the big one and creates the map using the Google Map API.  The directions.load is what loads the directions from the origin to the destination.  Now these values are passed in along the query string and are parsed using the gup function.   The print map simply hides the print button and sends the page to the printer.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;"&gt;Now let's look at a quick example, assuming we've named our file map.html.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: 14px; white-space: pre;"&gt;server.com/map.html?origin=&amp;amp;UTdestination=NV&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: 14px; white-space: pre;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: 14px; white-space: pre;"&gt;Will give us a map from Utah to Nevada.  You can enter full or partial address in standard JSON format.  If your addresses have spaces you will need to ensure that the URL is fully encoded for this to work.  I use asp.net so Server.UrlEncode is your friend.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: 14px; white-space: pre;"&gt;You can read more about the different APIs directly from Google.com&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: 14px; white-space: pre;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://code.google.com/apis/maps/index.html"&gt;http://code.google.com/apis/maps/index.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
And below is an image of the map generated above&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-rvrbsLiWl3w/TVl_aXne9DI/AAAAAAAAAGM/iC-IyUycmMs/s1600/map_example.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/-rvrbsLiWl3w/TVl_aXne9DI/AAAAAAAAAGM/iC-IyUycmMs/s320/map_example.PNG" width="226" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-7275555324060335559?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kRmccobsAHrMvQtFRfZiKHucg7Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kRmccobsAHrMvQtFRfZiKHucg7Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kRmccobsAHrMvQtFRfZiKHucg7Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kRmccobsAHrMvQtFRfZiKHucg7Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/eFlmlHEIvoY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/7275555324060335559/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=7275555324060335559&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/7275555324060335559?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/7275555324060335559?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/eFlmlHEIvoY/using-google-maps-api-for-driving.html" title="Using google maps API for driving directions" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-rvrbsLiWl3w/TVl_aXne9DI/AAAAAAAAAGM/iC-IyUycmMs/s72-c/map_example.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/02/using-google-maps-api-for-driving.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE8NRHYycCp7ImA9Wx9UF00.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-3552760347689854297</id><published>2011-02-14T10:01:00.000-07:00</published><updated>2011-02-14T10:01:35.898-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-14T10:01:35.898-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sql" /><category scheme="http://www.blogger.com/atom/ns#" term="databases" /><category scheme="http://www.blogger.com/atom/ns#" term="transactions" /><category scheme="http://www.blogger.com/atom/ns#" term="ODBC" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="mySQL" /><title>C# using a transaction with ODBC</title><content type="html">Let's say your writing some data to the database and you need to make it transactional. &amp;nbsp;You know where you need to rollback multiple statements or use multiple statements in one go. &amp;nbsp;Normally you would do this in the database itself. &amp;nbsp;But I have found a few times where you have to do this in .net. &amp;nbsp;My latest was using mySQL to get the new index after I did an insert. &amp;nbsp;I found the SQL to do so would work fine in a mySQL command prompt or in the phpMyAdmin SQL pane but their .net ODBC driver simply wouldn't allow it. &amp;nbsp;Epic .net fail mySQL I guess your love for PHP has clouded your vision. &amp;nbsp;So you end up needing to wrap up multiple SQL calls in a transaction to accomplish this. &amp;nbsp;I have also had to do this it SQLSERVER but not on a scale like this. &amp;nbsp;But regardless this is how you can use a .net transaction with multiple SQL statements.&lt;br /&gt;
&lt;br /&gt;
You need to create an OdbcConnection. &amp;nbsp;Then an OdbcCommand and OdbcTransaction. &amp;nbsp;Set the command and transactions connection to the connection opened earlier. &amp;nbsp;Then you call BeginTransaction on the transaction object and make all your SQL command calls. &amp;nbsp;When you're done you try and finalize the transaction or if any errors occurred rollback the transaction. &amp;nbsp;You can look at the code below for a good example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;
&lt;span style="color: green;"&gt;// open a new connection using a default connection string I have defined elsewhere&lt;/span&gt;
using( OdbcConnection connection = new OdbcConnection( s_connectionString ) )
{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="color: green;"&gt;// ODBC command and transaction objects&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;OdbcCommand command = new OdbcCommand();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;OdbcTransaction transaction = null;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="color: green;"&gt;// tell the command to use our connection&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;command.Connection = connection;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;try
&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="color: green;"&gt;// open the connection&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; connection.Open();

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;// start the transaction&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; transaction = connection.BeginTransaction();

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;// Assign transaction object for a pending local transaction.&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; command.Connection = connection;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; command.Transaction = transaction;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;// TODO: Build a SQL INSERT statement&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; StringBuilder SQL = new StringBuilder();

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;// run the insert using a non query call&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; command.CommandText = SQL.ToString();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; command.ExecuteNonQuery();

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;/* now we want to make a second call to MYSQL to get the new index&amp;nbsp;&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="color: green;"&gt;value it created for the primary key. &amp;nbsp;This is called using scalar so it will&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: green;"&gt;return the value of the SQL&amp;nbsp;&amp;nbsp;statement. &amp;nbsp;We convert that to an int for later use.*/&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; command.CommandText = "select last_insert_id();";
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id = Convert.ToInt32( command.ExecuteScalar() );

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;// Commit the transaction.&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; transaction.Commit();
&amp;nbsp;&amp;nbsp; &amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp; catch( Exception ex )
&amp;nbsp;&amp;nbsp; &amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Debug.WriteLine( ex.Message );

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try
&amp;nbsp;&amp;nbsp; &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="color: green;"&gt;&amp;nbsp;// Attempt to roll back the transaction.&lt;/span&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; transaction.Rollback();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;catch
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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="color: green;"&gt;// Do nothing here; transaction is not active.&lt;/span&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; }
}&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-3552760347689854297?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MfZi2ssj1HWwWyXiJmV8I8JrLD8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MfZi2ssj1HWwWyXiJmV8I8JrLD8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MfZi2ssj1HWwWyXiJmV8I8JrLD8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MfZi2ssj1HWwWyXiJmV8I8JrLD8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/oQyoXEnSmg4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/3552760347689854297/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=3552760347689854297&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/3552760347689854297?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/3552760347689854297?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/oQyoXEnSmg4/c-using-transaction-with-odbc.html" title="C# using a transaction with ODBC" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/02/c-using-transaction-with-odbc.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMHRXs-fCp7ImA9Wx9UEkU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-8911009196744463595</id><published>2011-02-09T14:20:00.000-07:00</published><updated>2011-02-09T14:20:34.554-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-09T14:20:34.554-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="GDI+" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Drawing" /><category scheme="http://www.blogger.com/atom/ns#" term="2d Drawing" /><title>C# Anti Aliasing when drawing</title><content type="html">In a previous post I talked about how to set anti-aliasing on text in C#.  Now you may find yourself needing to set anti aliasing when drawing shapes.  This is very easy to do using the GDI+ graphics object.  The trick is to use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.graphics.smoothingmode.aspx" target="_blank"&gt;SmoothingMode&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.graphics.pixeloffsetmode.aspx" target="_blank"&gt;PixelOffsetMode&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Now some quick code&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;protected override void OnPaint( PaintEventArgs e )
{
     e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
     e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
     e.Graphics.DrawEllipse( new Pen( new SolidBrush( Color.Red ), 1.0f ), new Rectangle( 5, 5, 200, 200 ) );

     e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
     e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
     e.Graphics.DrawEllipse( new Pen( new SolidBrush( Color.Red ), 1.0f ), new Rectangle( 210, 5, 200, 200 ) );

     e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
     e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
     e.Graphics.DrawEllipse( new Pen( new SolidBrush( Color.Red ), 1.0f ), new Rectangle( 415, 5, 200, 200 ) );

     e.Graphics.SmoothingMode = SmoothingMode.Default;
     e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
     e.Graphics.DrawEllipse( new Pen( new SolidBrush( Color.Red ), 1.0f ), new Rectangle( 620, 5, 200, 200 ) );


     base.OnPaint( e );
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_-2UfGbo6kWA/TVMEOo3B5-I/AAAAAAAAAGA/MkCNLafmsT4/s1600/circles.PNG" imageanchor="1" style=""&gt;&lt;img border="0" height="129" width="400" src="http://1.bp.blogspot.com/_-2UfGbo6kWA/TVMEOo3B5-I/AAAAAAAAAGA/MkCNLafmsT4/s400/circles.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now as you can see we start with the higher quality AA setting and move down to the default setting.  I kept the PixelOffsetMode to high quality for all tests.  You can play around with the different settings to achieve the desired results.  We do a lot of image generation and have them both set to as high as possible and don't see a large impact on drawing performance by using AA.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-8911009196744463595?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6mFHgsFjSdL-x8Cw4eOjvbYfMTo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6mFHgsFjSdL-x8Cw4eOjvbYfMTo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6mFHgsFjSdL-x8Cw4eOjvbYfMTo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6mFHgsFjSdL-x8Cw4eOjvbYfMTo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/dM7cNtugaVs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/8911009196744463595/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=8911009196744463595&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8911009196744463595?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8911009196744463595?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/dM7cNtugaVs/c-anti-aliasing-when-drawing.html" title="C# Anti Aliasing when drawing" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_-2UfGbo6kWA/TVMEOo3B5-I/AAAAAAAAAGA/MkCNLafmsT4/s72-c/circles.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/02/c-anti-aliasing-when-drawing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04HRH48eyp7ImA9Wx9VEk4.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-5149857855379065369</id><published>2011-01-28T09:20:00.001-07:00</published><updated>2011-01-28T09:25:35.073-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-28T09:25:35.073-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="GDI+" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Drawing" /><category scheme="http://www.blogger.com/atom/ns#" term="AntiAlias" /><category scheme="http://www.blogger.com/atom/ns#" term="2d Drawing" /><title>Antialiasing Text with C#</title><content type="html">Lately I have found myself having to use anti-aliasing in a lot of our rendering code to improve the output look our images. &amp;nbsp;To help others here is a snippet of code to anti alias text.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;protected override void OnPaint( PaintEventArgs e )
{
&amp;nbsp;&amp;nbsp; &amp;nbsp;base.OnPaint( e );
&amp;nbsp;&amp;nbsp; &amp;nbsp;Font font = new Font( "Tahoma", 12.0f, FontStyle.Regular );

&amp;nbsp;&amp;nbsp; &amp;nbsp;e.Graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
&amp;nbsp;&amp;nbsp; &amp;nbsp;TextRenderer.DrawText( e.Graphics, "Antialiased Text", font, new Point( 0,&amp;nbsp;20 ), Color.Black );

&amp;nbsp;&amp;nbsp; &amp;nbsp; e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
&amp;nbsp;&amp;nbsp; &amp;nbsp; TextRenderer.DrawText( e.Graphics, "Antialiased Text", font, new Point( 0,&amp;nbsp;40 ), Color.Black );

&amp;nbsp;&amp;nbsp; &amp;nbsp;e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
&amp;nbsp;&amp;nbsp; &amp;nbsp;TextRenderer.DrawText( e.Graphics, "Antialiased Text", font, new Point( 0,&amp;nbsp;60 ), Color.Black );

&amp;nbsp;&amp;nbsp; &amp;nbsp;e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
&amp;nbsp;&amp;nbsp; &amp;nbsp;TextRenderer.DrawText( e.Graphics, "Antialiased Text", font, new Point( 0,&amp;nbsp;80 ), Color.Black );
}&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
You can see the results below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_-2UfGbo6kWA/TULtrOodLlI/AAAAAAAAAF0/kD6NdXzBojY/s1600/AA.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_-2UfGbo6kWA/TULtrOodLlI/AAAAAAAAAF0/kD6NdXzBojY/s1600/AA.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The trick in the code above is the TextRenderingHint on the graphics object. &amp;nbsp;The 4 above are probably the most common but there are a few more. &amp;nbsp;You can read about them on MSDN:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.graphics.textrenderinghint.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.drawing.graphics.textrenderinghint.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
You can also anti alias drawing lines, circles, fills, etc but that will be covered in another post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-5149857855379065369?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cMma483imxQcBF4xWiJX1DL1seo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cMma483imxQcBF4xWiJX1DL1seo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cMma483imxQcBF4xWiJX1DL1seo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cMma483imxQcBF4xWiJX1DL1seo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/y7fnspFSRlQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/5149857855379065369/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=5149857855379065369&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5149857855379065369?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5149857855379065369?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/y7fnspFSRlQ/antialiasing-text-with-c.html" title="Antialiasing Text with C#" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_-2UfGbo6kWA/TULtrOodLlI/AAAAAAAAAF0/kD6NdXzBojY/s72-c/AA.PNG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2011/01/antialiasing-text-with-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8DQnkyfyp7ImA9Wx5bEEk.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-5091039332891974680</id><published>2010-10-25T14:57:00.000-07:00</published><updated>2010-10-25T14:57:53.797-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-25T14:57:53.797-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="DateTime" /><category scheme="http://www.blogger.com/atom/ns#" term="Formattting" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# Formatting DateTime to a String</title><content type="html">Often times you find yourself needing to convert a DateTime object into a useful string representation. &amp;nbsp;Here are some basic parameters to the DateTime.ToString() method.&lt;br /&gt;
&lt;br /&gt;
&lt;table cellpadding="2" cellspacing="1"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Tuesday, 25 August 2010 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;HH:mm Tuesday, 25 August 2010 06:30 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;hh:mm tt Tuesday, 25 August 2010 06:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;H:mm Tuesday, 25 August 2010 6:30 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;h:mm tt Tuesday, 25 August 2010 6:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy HH:mm:ss&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Tuesday, 25 August 2010 06:30:07 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy HH:mm&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 06:30 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy hh:mm tt&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 06:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy H:mm&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 6:30 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy h:mm tt&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 6:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy h:mm tt&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 6:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy h:mm tt&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 6:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MM/dd/yyyy HH:mm:ss&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;08/25/2010 06:30:07&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MMMM dd&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;August 25 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;MMMM dd&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;August 25 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;2010-08-25T06:30:07.7199252-04:00 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;2010-08-25T06:30:07.7199252-04:00 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;ddd, dd MMM yyyy HH':'mm':'ss 'GMT'&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Tue, 25 Aug 2010 06:30:07 GMT &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;ddd, dd MMM yyyy HH':'mm':'ss 'GMT'&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Tue, 25 Aug 2010 06:30:07 GMT &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;yyyy'-'MM'-'dd'T'HH':'mm':'ss&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;2010-08-25T06:30:07 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;HH:mm&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;06:30 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;hh:mm tt&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;06:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;H:mm&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;6:30 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;h:mm tt&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;6:30 AM &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;HH:mm:ss&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;06:30:07 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;yyyy'-'MM'-'dd HH':'mm':'ss'Z'&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;2010-08-25 06:30:07Z &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;dddd, dd MMMM yyyy HH:mm:ss&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Tuesday, 25 August 2010 06:30:07 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;yyyy MMMM&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;2010 August &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;yyyy MMMM&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;2010 August &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-5091039332891974680?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XgVqP5O9sAo1hSV4JwwTHoUsABo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XgVqP5O9sAo1hSV4JwwTHoUsABo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XgVqP5O9sAo1hSV4JwwTHoUsABo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XgVqP5O9sAo1hSV4JwwTHoUsABo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/CFcp_8VW05E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/5091039332891974680/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=5091039332891974680&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5091039332891974680?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5091039332891974680?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/CFcp_8VW05E/c-formatting-datetime-to-string.html" title="C# Formatting DateTime to a String" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/10/c-formatting-datetime-to-string.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMMRXo_eCp7ImA9Wx5XFUo.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-4014360062244340513</id><published>2010-09-15T12:21:00.000-07:00</published><updated>2010-09-15T12:21:24.440-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-15T12:21:24.440-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="message queues" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="MSMQ 3.0" /><category scheme="http://www.blogger.com/atom/ns#" term="msmq" /><category scheme="http://www.blogger.com/atom/ns#" term="com" /><title>C# get number of messages in message queue (MSMQ)</title><content type="html">Working with message queues in .net is incredibly easy. However I often find myself having to get the number of message in queue for monitoring, etc. That aspect of the message queue framework is a bit lacking. There are a few options available but they all have some problems.&lt;br /&gt;
&lt;br /&gt;
You can call GetAllMessages() right off the message queue object. This code works, however it gets a copy of EVERY message queue item currently in the queue. Got 10 items, you get ten. Now do this with 10,000 items every second and it starts to become a problem.&lt;br /&gt;
&lt;br /&gt;
It's also possible to enumerate through all the messages in the queue and take a count of them manually but if your queue is busy this can cause invalid cursor exceptions to happen. This is the main reason I moved away from doing this.&lt;br /&gt;
&lt;br /&gt;
You can also do some performance counter work but I find that code to be too complex and very fragile and prone to breakage.&lt;br /&gt;
&lt;br /&gt;
I've found the best bet is to go with the COM/Win32 route. The nice thing here is you don't have to do any PInoke calls but you do have to do some Marshalling. Now this code required the MSMQ 3.0 be installed. This is the latest version and should be fairly universal at this point in time.&lt;br /&gt;
&lt;br /&gt;
First add a reference to the MSMQ 3.0 Object library to your project.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/_-2UfGbo6kWA/TJEaBbBbO2I/AAAAAAAAAFo/VxdUKqhDCNM/s1600/add_ref.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" qx="true" src="http://4.bp.blogspot.com/_-2UfGbo6kWA/TJEaBbBbO2I/AAAAAAAAAFo/VxdUKqhDCNM/s320/add_ref.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now add a &lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"&gt;&lt;code&gt;using MSMQ;
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
statement to your class, etc.&lt;br /&gt;
&lt;br /&gt;
The magic happens in the MSMQManagement class. The code below uses a MessageQueue I have already set up as m_imgRequestQueue. You create a new MSMQManagement class and set it up and then call the Init method. The machine name and formatName parameters are the only required params so that is why the path is set to null. After init you can then use the MessageCount property to access the number of messages in the queue. And as with any COM object in .NET you must always release it when you're done with it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"&gt;&lt;code&gt; // setup the queue management COM stuff
MSMQManagement _queueManager = new MSMQManagement();

object machine = new object();
machine = m_imgRequestQueue.MachineName;

object path = null;

object formatName = new object();
formatName = m_imgRequestQueue.FormatName;

_queueManager.Init( ref machine, ref path, ref formatName );

// once inited you can use the MessageCount property (int) to get the]
// number of messages in the queue
_queueManager.MessageCount

// ALWAYS release COM objects when you're done with them
Marshal.ReleaseComObject( _queueManager );

&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-4014360062244340513?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wK6H5_3fnfMNh_sU0aQetashZ1w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wK6H5_3fnfMNh_sU0aQetashZ1w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wK6H5_3fnfMNh_sU0aQetashZ1w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wK6H5_3fnfMNh_sU0aQetashZ1w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/cqtO11NX_Uc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/4014360062244340513/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=4014360062244340513&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4014360062244340513?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4014360062244340513?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/cqtO11NX_Uc/c-get-number-of-messages-in-message.html" title="C# get number of messages in message queue (MSMQ)" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_-2UfGbo6kWA/TJEaBbBbO2I/AAAAAAAAAFo/VxdUKqhDCNM/s72-c/add_ref.JPG" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/09/c-get-number-of-messages-in-message.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEFQn45fip7ImA9Wx9UEkU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-4298904796077694065</id><published>2010-07-27T09:22:00.001-07:00</published><updated>2011-02-09T14:23:33.026-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-09T14:23:33.026-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Serialization" /><category scheme="http://www.blogger.com/atom/ns#" term="XML" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>C# Serialize an object to/from XML</title><content type="html">There have been many times I've needed to serialize an object to/from XML.  .NET makes this incredibly easy.  With a few meta tags your class(es) can easily be serialized and deserialized.  You can then take this even further any start applying custom attributes to have as much granular control over the serialization as you want.&lt;br /&gt;
&lt;br /&gt;
For instance lets' take a very basic class with some data and properties.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public class Person
{
    int _age;
    String _name;

    /// Gets or sets the Age of the person.
    public int Age
    {
       get { return _age; }
       set { _age = value; }
    }

    /// Gets or sets the Name of the person.
    public String Name
    {
       get { return _name; }
       set { _name = value; }
    }

    /// Creates a new instance of the Person class
    public Person()
    {
    }

}
&lt;/code&gt;&lt;/pre&gt;Now let's take this class and add the [Serializable] attribute.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;[Serializable]
public class Person
{
    int _age;
    String _name;

    /// Gets or sets the Age of the person.
    public int Age
    {
       get { return _age; }
       set { _age = value; }
    }

    /// Gets or sets the Name of the person.
    public String Name
    {
       get { return _name; }
       set { _name = value; }
    }

    /// Creates a new instance of the Person class
    public Person()
    {
    }

}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
You can now take this class to/from XML.  When you serialize it the .net parser will look at all public properties and fields and convert them to XML.  &lt;br /&gt;
&lt;br /&gt;
You will end up with XML that will look like the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;xml version=&amp;quot;1.0&amp;quot; /&amp;gt;
&amp;lt;Person&amp;gt;
&amp;lt;Age&amp;gt;X&amp;lt;/Age&amp;gt;
&amp;lt;Name&amp;gt;Y&amp;lt;/Age&amp;gt;
&amp;lt;/Person&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Whatever values you have stored in the name and age fields will be written to the XML.  &lt;br /&gt;
&lt;br /&gt;
Obviously this is a very primitive example of what you can do to get your classes into XML.  There are a wide variety of XML Attributes you can apply to your classes to more fully control the serialization.  This is a basic example of how to get your class into and back from XML.&lt;br /&gt;
&lt;br /&gt;
A quite note on data types.  All the .net value types (int, String, etc) can be converted to XML; however some of the more complex reference types (classes) may not be convertible.  Be careful when serializing all your properties, etc fully support serialization.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-4298904796077694065?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UxcsCUcl2qItqYe_TrqSXWiBmLU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UxcsCUcl2qItqYe_TrqSXWiBmLU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UxcsCUcl2qItqYe_TrqSXWiBmLU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UxcsCUcl2qItqYe_TrqSXWiBmLU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/v7SHcdf0_ds" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/4298904796077694065/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=4298904796077694065&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4298904796077694065?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/4298904796077694065?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/v7SHcdf0_ds/c-serialize-object-tofrom-xml.html" title="C# Serialize an object to/from XML" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/07/c-serialize-object-tofrom-xml.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUINSHwyfip7ImA9WxFXF04.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-8049669549340459122</id><published>2010-05-24T13:38:00.002-07:00</published><updated>2010-05-24T13:39:59.296-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-24T13:39:59.296-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Strings" /><title>C# Equal vs CompareTo</title><content type="html">Out of curiosity I decided to run some speed tests on strings using the Equals and CompareTo methods.  I wrote some quick code and came up with some interesting results:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/_-2UfGbo6kWA/S_riENMfZTI/AAAAAAAAAFY/UOyDPLR873E/s1600/times.PNG" target="_blank" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="207" src="http://4.bp.blogspot.com/_-2UfGbo6kWA/S_riENMfZTI/AAAAAAAAAFY/UOyDPLR873E/s400/times.PNG" width="400" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test was run for 10000000 iterations.  The Equals methods trounced the CompareTo method.  Under the hood Equals stops when the first character that doesn't match is found.  CompareTo continues on to the end of the string all the time.  However this was a case insensitive search with no culture information.  Adding more variables may cloud the water a bit, but that is going to be reserved for future posts.  The code used in the test can be seen below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Threading;

namespace Sandbox
{
    class Program
    {
        static void Main( string[] args )
        {
            const int counter = 10000000;

            int i = 0;

            int count = 0;

            String string1 = "ASq2qw;m;kl1212ed'12,12lml!@)Eki3";
            String string2 = "AS@_)#L:;sladf-030-!+)I@1=0-23i1[pk1=-12i=}";
            String string3 = "ASq2qw;m;kl1212ed'12,12lml!@)Eki3";

            DateTime start;

            TimeSpan span;

            // run some string comparisons
            Console.WriteLine( "Running tests" );
            Console.WriteLine();

            // first test Equals on strings that aren't equal one another
            start = DateTime.Now;

            for( i = 0; i &amp;lt; counter; i++ )
            {
                if( string1.Equals( string2 ) )
                {
                    count++;
                }
            }

            span = DateTime.Now - start;
            Console.WriteLine( "Strings that aren't equal using Equals() : " + span.TotalSeconds );
            
            // second test using CompareTo on strings that aren't equal
            start = DateTime.Now;

            for( i = 0; i &amp;lt; counter; i++ )
            {
                if( string1.CompareTo( string2 ) == 0 )
                {
                    count++;
                }
            }

            span = DateTime.Now - start;
            Console.WriteLine( "Strings that aren't equal using CompareTo() : " + span.TotalSeconds );

            // third test using Equals on strings that are equal
            start = DateTime.Now;

            for( i = 0; i &amp;lt; counter; i++ )
            {
                if( string1.Equals( string3 ) )
                {
                    count++;
                }
            }

            span = DateTime.Now - start;
            Console.WriteLine( "Strings that are equal using Equals() : " + span.TotalSeconds );

            // fourth test using CompareTo on strings that are equal
            start = DateTime.Now;

            for( i = 0; i &amp;lt; counter; i++ )
            {
                if( string1.CompareTo( string3 ) == 0 )
                {
                    count++;
                }
            }

            span = DateTime.Now - start;
            Console.WriteLine( "Strings that are equal using CompareTo() : " + span.TotalSeconds );
            Console.WriteLine();
            Console.WriteLine( "Press any key to continue . . ." );
            Console.ReadKey();

        }
    }
}

&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-8049669549340459122?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Cn69pgzvNbXrh6-m-D42c_KG5r0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Cn69pgzvNbXrh6-m-D42c_KG5r0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Cn69pgzvNbXrh6-m-D42c_KG5r0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Cn69pgzvNbXrh6-m-D42c_KG5r0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/_B72VhXcJGI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/8049669549340459122/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=8049669549340459122&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8049669549340459122?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8049669549340459122?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/_B72VhXcJGI/c-equal-vs-compareto.html" title="C# Equal vs CompareTo" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_-2UfGbo6kWA/S_riENMfZTI/AAAAAAAAAFY/UOyDPLR873E/s72-c/times.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/05/c-equal-vs-compareto.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkEAQHY9cSp7ImA9WxFQGEg.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-2880891923689510865</id><published>2010-05-14T08:24:00.000-07:00</published><updated>2010-05-14T08:24:01.869-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-14T08:24:01.869-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Visual C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="BackgroundWorker" /><title>C# using a background worker</title><content type="html">This post is going to focus on creating and using a BackgroundWorker object.  Background workers are found in the System.ComponentModel namespace.  They're pretty easy to use.  You just create a new object, assign a few properties and event handlers and let it do its thing.&lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.ComponentModel;&lt;br /&gt;
&lt;br /&gt;
First let's create a background worked object and set it up.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Pstatic void Main( string[] args
{
   // create the background worker object
   BackgroundWorker _worker = new BackgroundWorker();

   // tell the background worker it can be cancelled and report progress
   _worker.WorkerReportsProgress = true;
   _worker.WorkerSupportsCancellation = true;

   // a worker thread object where the actual work happens
   WorkerThread thread = new WorkerThread();

   // add our event handlers
   _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( thread.RunWorkerCompleted );
   _worker.ProgressChanged += new ProgressChangedEventHandler( thread.ProgressChanged );
   _worker.DoWork += new DoWorkEventHandler( thread.DoWork );

   // start the worker thread
   _worker.RunWorkerAsync();

   // wait for it to be completed
   while( !_worker.CancellationPending )
   {
      // sleep for a second
      Thread.Sleep( 1000 );
    }

    Console.ReadKey();

}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
There are two properties WorkerReportsProgress and WorkerSupportsCancellation.  These are set to false by default.  You will need to set them to true if you want to be able to get progress reports back from the worker or cancel it before the work is done.&lt;br /&gt;
&lt;br /&gt;
Now the next section is a class that actually does the work.  I called mine ThreadWorker but it can be anything.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public class WorkerThread
{
    public void DoWork( object sender, DoWorkEventArgs e )
    {
       //get a handle on the worker that started this request
       BackgroundWorker workerSender = sender as BackgroundWorker;

       // loop through 10 times and report the progress back to the sending object
       for( int i = 0; i &amp;lt; 10; i++ )
       {
          // tell the worker that we want to report progress being made
          workerSender.ReportProgress( i );
          Thread.Sleep( 100 );
       }

       // cancel the thread and send back that we cancelled
       workerSender.CancelAsync();
       e.Cancel = true;

    }

    public void RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e )
    {
       Console.WriteLine( &amp;quot;Worker Done!!&amp;quot; );          
    }

    public void ProgressChanged( object sender, ProgressChangedEventArgs e )
    {
      // print out the percent changed
      Console.WriteLine( e.ProgressPercentage );
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Notice the three methods correspond to the 3 event handlers above.  When creating the BackgroundWorker you can tell it what methods to call for certain events.  I prefer to use a class that is built specifically for those events.&lt;br /&gt;
&lt;br /&gt;
So I hope this helps people figure out and use BackgroundWorker objects.  I find them very handy especially in UI programming when I need to report on how much work is being done, etc.  Or when I need to be able to know when a thread is done and have the ability to cancel it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-2880891923689510865?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/v8_LkMP1jk47rANQ5XBnMkJhrEk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/v8_LkMP1jk47rANQ5XBnMkJhrEk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/v8_LkMP1jk47rANQ5XBnMkJhrEk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/v8_LkMP1jk47rANQ5XBnMkJhrEk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/F93XuMVMznc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/2880891923689510865/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=2880891923689510865&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/2880891923689510865?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/2880891923689510865?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/F93XuMVMznc/c-using-background-worker.html" title="C# using a background worker" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/05/c-using-background-worker.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYFQ3g-fyp7ImA9WxFSEkU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-8097533284543133880</id><published>2010-04-14T15:07:00.003-07:00</published><updated>2010-04-14T15:11:52.657-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-14T15:11:52.657-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Design Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Singleton" /><title>C# Creating a Singleton</title><content type="html">A lot of people talk trash about the Singleton and how it should be avoided like the plague.  I think like a lot of things it has its place and can be used effectively in certain situations. I'm going to leave what those situations are alone for the time being and just focus on creating a nice thread safe lazy init singleton class.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public sealed class Singleton&lt;br /&gt;{&lt;br /&gt;    Singleton()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static Singleton Instance&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return Nested.instance;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    class Nested&lt;br /&gt;    {&lt;br /&gt;        // Use an explicit static constructor to tell the C# compiler&lt;br /&gt;        // not to mark type as beforefieldinit&lt;br /&gt;        static Nested()&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        internal static readonly Singleton instance = new Singleton();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-8097533284543133880?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VN0ck4UqFr9ZYLsuUFRuLkyUeS4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VN0ck4UqFr9ZYLsuUFRuLkyUeS4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VN0ck4UqFr9ZYLsuUFRuLkyUeS4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VN0ck4UqFr9ZYLsuUFRuLkyUeS4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/6YiwtWtvVRM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/8097533284543133880/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=8097533284543133880&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8097533284543133880?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/8097533284543133880?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/6YiwtWtvVRM/c-creating-singleton.html" title="C# Creating a Singleton" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/04/c-creating-singleton.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04GSHo8cSp7ImA9WxFTFkU.&quot;"><id>tag:blogger.com,1999:blog-32773047.post-5135341305922048493</id><published>2010-04-07T15:51:00.005-07:00</published><updated>2010-04-07T16:12:09.479-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-07T16:12:09.479-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="custom collections" /><category scheme="http://www.blogger.com/atom/ns#" term="DataGridView" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="DataBinding" /><title>Binding to a DataGridView with a custom collection</title><content type="html">Often times I find the need to bind a custom collection to a datagridview in a windows form.  .Net makes this easy and with some simple code we can achieve some pretty quick results.&lt;br /&gt;&lt;br /&gt;First drop a DataGridView onto your form.  Click the little white arrow on the top right of the grid and select Choose Data Source.  This should bring up wizard that allows you to select what you want to bind to the grid.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-2UfGbo6kWA/S70Ok0mgpDI/AAAAAAAAAFA/E4LBF9P3ynY/s1600/step1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 252px; height: 254px;" src="http://3.bp.blogspot.com/_-2UfGbo6kWA/S70Ok0mgpDI/AAAAAAAAAFA/E4LBF9P3ynY/s400/step1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5457534349201155122" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-2UfGbo6kWA/S70OptaJshI/AAAAAAAAAFI/1a-RbiNYM58/s1600/step2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 312px;" src="http://3.bp.blogspot.com/_-2UfGbo6kWA/S70OptaJshI/AAAAAAAAAFI/1a-RbiNYM58/s400/step2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5457534433169617426" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Select Object and click Next.  Now select the class you want to bind too.  You can select from all the existing references in your project or add a new one by clicking Add Reference.  When you've selected the class to use click the Finish button.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_-2UfGbo6kWA/S70Oxyrf3-I/AAAAAAAAAFQ/DN86zqtTU3s/s1600/step3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 314px;" src="http://2.bp.blogspot.com/_-2UfGbo6kWA/S70Oxyrf3-I/AAAAAAAAAFQ/DN86zqtTU3s/s400/step3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5457534572023504866" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now that you've got the design done let's write some code to show our data in the grid.  I have created a custom collection called Playlists that contains a list of Playlist items.  My datagrid is bound to this collection and uses its public properties as the values for the columns.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public class Playlist&lt;br /&gt;    {&lt;br /&gt;        private String _title = String.Empty;&lt;br /&gt;        private String _directory = String.Empty;&lt;br /&gt;&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Gets or sets the name.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;value&amp;gt;The name.&amp;lt;/value&amp;gt;&lt;br /&gt;        public String Title&lt;br /&gt;        {&lt;br /&gt;            get { return _title; }&lt;br /&gt;            set { _title = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Gets or sets the directory.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;value&amp;gt;The directory.&amp;lt;/value&amp;gt;&lt;br /&gt;        public String Directory&lt;br /&gt;        {&lt;br /&gt;            get { return _directory; }&lt;br /&gt;            set { _directory = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Initializes a new instance of the &amp;lt;see cref=&amp;quot;Playlist&amp;quot;/&amp;gt; class.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        public Playlist()&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Initializes a new instance of the &amp;lt;see cref=&amp;quot;Playlist&amp;quot;/&amp;gt; class.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;param name=&amp;quot;ID&amp;quot;&amp;gt;The ID.&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;param name=&amp;quot;title&amp;quot;&amp;gt;The title.&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;param name=&amp;quot;Directory&amp;quot;&amp;gt;The directory.&amp;lt;/param&amp;gt;&lt;br /&gt;        public Playlist( int ID, String title, String Directory )&lt;br /&gt;        {&lt;br /&gt;            _playlistID = ID;&lt;br /&gt;            _title = title;&lt;br /&gt;            _directory = Directory;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Returns a &amp;lt;see cref=&amp;quot;System.String&amp;quot;/&amp;gt; that represents this instance.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;returns&amp;gt;&lt;br /&gt;        /// A &amp;lt;see cref=&amp;quot;System.String&amp;quot;/&amp;gt; that represents this instance.&lt;br /&gt;        /// &amp;lt;/returns&amp;gt;&lt;br /&gt;        public override string ToString()&lt;br /&gt;        {&lt;br /&gt;            return base.ToString();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The collection class&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public class Playlists:Collection&amp;lt;Playlist&amp;gt;&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now in the forms code behind you set the actual instance of the collection you want to bind as the BidingSource's DataSource.  My BindingSource is called playlistsBindingSource.  You can name it whatever you want when you're creating it in the above steps.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;// create a custom collection&lt;br /&gt;private Playlists _playLists = new Playlists();&lt;br /&gt;&lt;br /&gt;// TODO: add some items to the collection&lt;br /&gt;&lt;br /&gt;// set the binding sources data source to our collection&lt;br /&gt;this.playlistsBindingSource.DataSource = _playLists;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now you can add/remove items from the binding source just as you would the collection. It has the same Add, Remove, RemoveAt functions a generic collection container does and your datagrid will automatically update its displayed items.  You can even find get the actual object used to databind to each row and use its data if you need to.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/32773047-5135341305922048493?l=justins-fat-tire.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TrufDNEbR9KO3GRz5ZtALzo40RM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TrufDNEbR9KO3GRz5ZtALzo40RM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TrufDNEbR9KO3GRz5ZtALzo40RM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TrufDNEbR9KO3GRz5ZtALzo40RM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JustinsFatTire/~4/9bvCNVXyigI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://justins-fat-tire.blogspot.com/feeds/5135341305922048493/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=32773047&amp;postID=5135341305922048493&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5135341305922048493?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/32773047/posts/default/5135341305922048493?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JustinsFatTire/~3/9bvCNVXyigI/binding-to-datagridview-with-custom.html" title="Binding to a DataGridView with a custom collection" /><author><name>Justin</name><uri>http://www.blogger.com/profile/14670970446696919360</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://photos1.blogger.com/blogger/5286/416/1600/lecheminant-justin.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_-2UfGbo6kWA/S70Ok0mgpDI/AAAAAAAAAFA/E4LBF9P3ynY/s72-c/step1.JPG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://justins-fat-tire.blogspot.com/2010/04/binding-to-datagridview-with-custom.html</feedburner:origLink></entry></feed>

