<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-13442121</id><updated>2007-08-02T11:58:01.240-07:00</updated><title type='text'>C# Programming</title><link rel='alternate' type='text/html' href='http://www.calcaria.net/c-sharp/'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.calcaria.net/c-sharp/atom.xml'/><author><name>Paul Maddox</name></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-13442121.post-116171370498426928</id><published>2006-10-24T11:04:00.000-07:00</published><updated>2006-10-24T11:15:05.006-07:00</updated><title type='text'>C# equivalent CSingleLock / Critical Section</title><content type='html'>C# has a pretty nifty way to perform critical section locking using the newly created 'lock' statement. For those of you after the quick answer:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Object lockobj = new Object();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;lock (lockobj)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#009900;"&gt;    // Do your locked work&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;br /&gt;To offer a bit more information..&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When would you use this?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Critical sections are used when you need to operate on objects, files, or other resources such as database and TCP connections across a number of threads.&lt;br /&gt;&lt;br /&gt;If you have multiple threads all trying to write to a file at the same time, for instance (say a log file), what happens if threads try writing at the same time?  One thread may get an exception saying it cannot open the file, or worse you may end up losing data if you don't correctly catch the exception.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How does it work?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Quite simply the lock statement will check if the object is locked and if it is it will wait.  Once the existing lock is relinquished the waiting thread will then move into the code within the braces and perform its operations.&lt;br /&gt;&lt;br /&gt;If you want the full technical details please visit the &lt;a href="http://msdn2.microsoft.com/en-us/library/c5kehkcz.aspx" target=_blank&gt;MSDN&lt;/a&gt;.</content><link rel='alternate' type='text/html' href='http://www.calcaria.net/c-sharp/2006/10/c-equivalent-csinglelock-critical.html' title='C# equivalent CSingleLock / Critical Section'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=13442121&amp;postID=116171370498426928' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.calcaria.net/c-sharp/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/116171370498426928'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/116171370498426928'/><author><name>Paul Maddox</name></author></entry><entry><id>tag:blogger.com,1999:blog-13442121.post-114623329706851230</id><published>2006-04-28T07:02:00.000-07:00</published><updated>2006-04-28T07:08:17.080-07:00</updated><title type='text'>Copying one string array to another</title><content type='html'>Say you have an array origArray declared as:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;string[] origArray;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;that contains a number of string items created, for example, like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;origArray = csvLine.Split(',');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I wanted to copy those strings into a new array dependent on some criteria.  This can be achieved as so:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#009900;"&gt;// Create new empty array&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;string[] outArray = new string[origArray.Length];&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;for (int i = 0; i &lt;&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;     outArray[i] = (string)tagArray[i].Clone();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;(I'm missing my criteria, but I have an if statement before I do the clone and do something else otherwise.)</content><link rel='alternate' type='text/html' href='http://www.calcaria.net/c-sharp/2006/04/copying-one-string-array-to-another.html' title='Copying one string array to another'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=13442121&amp;postID=114623329706851230' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.calcaria.net/c-sharp/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/114623329706851230'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/114623329706851230'/><author><name>Paul Maddox</name></author></entry><entry><id>tag:blogger.com,1999:blog-13442121.post-114312072185234491</id><published>2006-03-23T05:26:00.000-08:00</published><updated>2006-03-23T05:32:01.890-08:00</updated><title type='text'>Running command line apps from C#</title><content type='html'>Here's a great article on the MSDN blog for how to run a command line app from your C# code.  Here it is:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/archive/2004/06/01/146375.aspx"&gt;http://blogs.msdn.com/csharpfaq/archive/2004/06/01/146375.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you want the quick NON-SYCHRONOUS method, try:&lt;br /&gt;&lt;br /&gt;System.Diagnostics.Process.Start(@"c:\myscript.bat");</content><link rel='alternate' type='text/html' href='http://www.calcaria.net/c-sharp/2006/03/running-command-line-apps-from-c.html' title='Running command line apps from C#'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=13442121&amp;postID=114312072185234491' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.calcaria.net/c-sharp/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/114312072185234491'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/114312072185234491'/><author><name>Paul Maddox</name></author></entry><entry><id>tag:blogger.com,1999:blog-13442121.post-114251855783506676</id><published>2006-03-16T06:12:00.000-08:00</published><updated>2006-03-16T06:15:57.853-08:00</updated><title type='text'>Convert char[] to string</title><content type='html'>char[] is quite convenient if you're reading file data using StreamReader, but it doesn't offer the same functionality as string does.  Here's one way I've found of converting:&lt;br /&gt;&lt;br /&gt;char[] charBuf = new char[1024];  &lt;span style="color:#006600;"&gt;// Example char array&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;string s = "";  &lt;span style="color:#006600;"&gt;// Example empty string&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;s = new string(charBuf);  &lt;span style="color:#006600;"&gt;// Create new string passing charBuf into the constructor&lt;/span&gt;</content><link rel='alternate' type='text/html' href='http://www.calcaria.net/c-sharp/2006/03/convert-char-to-string.html' title='Convert char[] to string'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=13442121&amp;postID=114251855783506676' title='4 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.calcaria.net/c-sharp/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/114251855783506676'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/114251855783506676'/><author><name>Paul Maddox</name></author></entry><entry><id>tag:blogger.com,1999:blog-13442121.post-111800241618682308</id><published>2005-06-05T13:06:00.000-07:00</published><updated>2005-06-05T13:13:36.186-07:00</updated><title type='text'>CString::Find C# equivalent</title><content type='html'>The C# equivalent of CString::Find is IndexOf, which works for both string and System.String.&lt;br /&gt;&lt;br /&gt;Code in Visual C++ / MFC:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;CString sData = "http://www.calcaria.net";&lt;br /&gt;&lt;br /&gt;int iColonPos = sData.Find(":");&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Code in C#:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;string sData = "http://www.calcaria.net";&lt;br /&gt;&lt;br /&gt;int iColonPos = sData.IndexOf(":")&lt;/pre&gt;</content><link rel='alternate' type='text/html' href='http://www.calcaria.net/c-sharp/2005/06/cstringfind-c-equivalent.html' title='CString::Find C# equivalent'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=13442121&amp;postID=111800241618682308' title='0 Comments'/><link rel='replies' type='application/atom+xml' href='http://www.calcaria.net/c-sharp/atom.xml' title='Post Comments'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/111800241618682308'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/13442121/posts/default/111800241618682308'/><author><name>Paul Maddox</name></author></entry></feed>