<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>On technology and development &#187; .net</title>
	<atom:link href="http://blog.codewrench.net/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codewrench.net</link>
	<description>My thoughs on stuff</description>
	<lastBuildDate>Wed, 18 Jan 2012 07:49:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Silverlight 3</title>
		<link>http://blog.codewrench.net/2009/03/26/silverlight-3/</link>
		<comments>http://blog.codewrench.net/2009/03/26/silverlight-3/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 13:59:20 +0000</pubDate>
		<dc:creator>Pål</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://blog.paks.no/?p=123</guid>
		<description><![CDATA[Microsoft has just released the first beta of Silverlight 3. I encourage you to check out  Tim Heuer&#8217;s great guide to the new features.]]></description>
			<content:encoded><![CDATA[<p>Microsoft has just released the first beta of Silverlight 3. I encourage you to check out  Tim Heuer&#8217;s great <a href="http://timheuer.com/blog/archive/2009/03/18/silverlight-3-whats-new-a-guide.aspx">guide to the new features</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codewrench.net/2009/03/26/silverlight-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the oldest file</title>
		<link>http://blog.codewrench.net/2009/03/04/find-the-oldest-file/</link>
		<comments>http://blog.codewrench.net/2009/03/04/find-the-oldest-file/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 21:56:00 +0000</pubDate>
		<dc:creator>Pål</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dos]]></category>

		<guid isPermaLink="false">http://importdump.wordpress.com/2009/03/04/find-the-oldest-file/</guid>
		<description><![CDATA[I had a problem at work the other day. In a project we have a service that needs to handle files on a first come, first served basis. In effect it scans a folder for files and find the file &#8230; <a href="http://blog.codewrench.net/2009/03/04/find-the-oldest-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had a problem at work the other day. In a project we have a service that needs to handle files on a first come, first served basis. In effect it scans a folder for files and find the file with the oldest last modified stamp, then it processes the file.</p>
<p>This seems a simple enough task, but once when the service was down for a long time the number of files waiting to be processed was huge (in the several hundred thousand range). Scanning a folder with that many files in C# and then determining the oldest one takes quite a long time.</p>
<p>So I took a look at three different methods for solving this simple task.</p>
<p>1. Using the DirectoryInfo.GetFiles function<br />
2. Using the Directoty.GetFiles and then Directory.GetLastWriteTime on each file<br />
3. Using plain old DOS dir command</p>
<p>For 50.000 files the first two options takes about 7 seconds each on my development machine. While using dir takes only 0.7 seconds. Thats 10 times the performance difference.</p>
<p>This is how I managed to tweak dir to do the work:</p>
<pre>static string ScanFilesUsingDir(string filePath)
{
   string cmd = @"c:\Windows\System32\cmd.exe";
   string args = @"/C \"dir " + filePath + " /B /O:D /T:W\"";

   Process proc = new System.Diagnostics.Process();
   proc.EnableRaisingEvents = false;
   proc.StartInfo.CreateNoWindow = false;
   proc.StartInfo.FileName = cmd;
   proc.StartInfo.Arguments = args;
   proc.StartInfo.RedirectStandardOutput = true;
   proc.StartInfo.UseShellExecute = false;
   proc.Start();

   // Display returned console information if any
   StreamReader dirOutput = proc.StandardOutput;
   string oldestFile = dirOutput.ReadLine();
   dirOutput.Close();</pre>
<pre>   proc.Kill();
   return oldestFile;
}</pre>
<p>Oldest file found: f9e41b18-efa8-49ee-9a51-a89f7ef514ee.tmp<br />
Activity &#8216;Using DirectgoryInfo&#8217; took 00:00:07.0810000</p>
<p>Oldest file found: f9e41b18-efa8-49ee-9a51-a89f7ef514ee.tmp<br />
Activity &#8216;Using FileInfo&#8217; took 00:00:07.2710000</p>
<p>Oldest file found: f9e41b18-efa8-49ee-9a51-a89f7ef514ee.tmp<br />
Activity &#8216;Using Shell Dir&#8217; took 00:00:00.7030000</p>
<p>Just goes to show that POD (Plain Old Dos) still is good for something <img src='http://blog.codewrench.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Complete source code: <a href="http://www.fileqube.com/file/EhaModI177391">FileGenerator.rar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codewrench.net/2009/03/04/find-the-oldest-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

