<?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/"
	>

<channel>
	<title>Philosophical Geek</title>
	<atom:link href="http://www.philosophicalgeek.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philosophicalgeek.com</link>
	<description>Code and musings by Ben Watson</description>
	<pubDate>Tue, 30 Jun 2009 14:22:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Photos from the 2009 Seattle Rock and Roll Marathon and Half Marathon</title>
		<link>http://www.philosophicalgeek.com/2009/06/29/photos-from-the-2009-seattle-rock-and-roll-marathon-and-half-marathon/</link>
		<comments>http://www.philosophicalgeek.com/2009/06/29/photos-from-the-2009-seattle-rock-and-roll-marathon-and-half-marathon/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 02:42:14 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/06/29/photos-from-the-2009-seattle-rock-and-roll-marathon-and-half-marathon/</guid>
		<description><![CDATA[ On Saturday, my wife ran in the Rock and Roll Marathon in downtown Seattle. I roamed around and took pictures of Qwest and Safeco fields and snapped a few of the race itself. Bib numbers I captured (where I could read them) are: 3, 4, 5, 7, 9, 11, 15, 1275, 1347, 1350, 1356, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2009/06/dsc3557.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="_DSC3557" border="0" alt="_DSC3557" align="left" src="http://www.philosophicalgeek.com/wp-content/uploads/2009/06/dsc3557-thumb.jpg" width="244" height="151" /></a> On Saturday, my wife ran in the <a href="http://www.rnrseattle.com/">Rock and Roll Marathon</a> in downtown Seattle. I roamed around and <a href="http://benwatson.org/galleries/race/">took pictures</a> of Qwest and Safeco fields and snapped a few of the race itself. Bib numbers I captured (where I could read them) are: 3, 4, 5, 7, 9, 11, 15, 1275, 1347, 1350, 1356, 1412, 1470, 1490, 1498, 1539, 1573, 1580, 1611, 1690, 1695, 1707, 1710, 2042, 2449, 2470, 2494, 2513, 2575, 2642, 2723, 3512, 3610, 4318, 4498, 5227, 5335, 6671, 7412, 9335, 11419, 12487, 13512, 13610, 23556, 25480, 28560, 29588, 34389, 35366, F1, F2, F4, F5, F7, F8, F9, F14.</p>
<p>If you see yourself in any of these, I’ll e-mail you what I have for no charge. I won’t do any processing on them, other than what I already have, however.</p>
<p><a href="http://benwatson.org/galleries/race/">Gallery</a></p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2009/06/29/photos-from-the-2009-seattle-rock-and-roll-marathon-and-half-marathon/feed/</wfw:commentRss>
		</item>
		<item>
		<title>First Bing.com commercial</title>
		<link>http://www.philosophicalgeek.com/2009/06/03/first-bingcom-commercial/</link>
		<comments>http://www.philosophicalgeek.com/2009/06/03/first-bingcom-commercial/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 17:18:55 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Bing]]></category>

		<category><![CDATA[Link/News]]></category>

		<category><![CDATA[Live Search]]></category>

		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/06/03/first-bingcom-commercial/</guid>
		<description><![CDATA[Working on Bing.com for the last 9 months or so has been exhilarating. Finally, we can show the world the great stuff we’ve been doing. Here is (I think) the first TV commercial about Bing.com, running as of today.

I kissed Google goodbye more than a year ago and haven’t looked back. I think once people [...]]]></description>
			<content:encoded><![CDATA[<p>Working on <a href="http://www.bing.com">Bing.com</a> for the last 9 months or so has been exhilarating. Finally, we can show the world the great stuff we’ve been doing. Here is (I think) the first TV commercial about Bing.com, running as of today.</p>
<p><iframe height="334" src="http://www.microsoft.com/presspass/silverlightApps/videoplayer2/standalone.aspx?contentId=BingAd&amp;src=/Presspass/videos/playlists/2009/06-03bing.xml&amp;WT.cg_n=videoplayer&amp;WT.z_convert=embed" frameborder="0" width="400" scrolling="no"></iframe></p>
<p>I kissed Google goodbye more than a year ago and haven’t looked back. I think once people start using Bing, they’re going to do the same. </p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2009/06/03/first-bingcom-commercial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New apps and features from Live Search</title>
		<link>http://www.philosophicalgeek.com/2009/02/20/new-apps-and-features-from-live-search/</link>
		<comments>http://www.philosophicalgeek.com/2009/02/20/new-apps-and-features-from-live-search/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 23:07:17 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Link/News]]></category>

		<category><![CDATA[Live Search]]></category>

		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/02/20/new-apps-and-features-from-live-search/</guid>
		<description><![CDATA[I’ve been meaning to highlight a few of the cool things we’re doing in Live Search. I don’t have any direct involvement in the development of any of these—I just think they’re cool.
Answer Suggestions for IE8
IE8 is awesome, so go get it. Live Search has these things called Instant Answers where it can respond with [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been meaning to highlight a few of the cool things we’re doing in <a href="http://www.live.com">Live Search</a>. I don’t have any direct involvement in the development of any of these—I just think they’re cool.</p>
<h2>Answer Suggestions for IE8</h2>
<p>IE8 is awesome, so go <a href="http://www.microsoft.com/windows/internet-explorer/beta/default.aspx">get it</a>. Live Search has these things called <a href="http://help.live.com/help.aspx?project=wl_searchv1&amp;market=en-us&amp;querytype=topic&amp;query=wl_search_ref_instantanswers.htm">Instant Answers</a> where it can respond with succinct answers to your question, rather than just web pages that may have the answer. Good examples are weather and numeric conversions—you just want to know the answers, not necessarily follow links to find it.</p>
<p>You get normal search suggestions of course, but the cool thing is that the display of the instant answers is built right into IE8. You can type into the search box and have the answers returned right in the drop down as you type. Here are some samples:</p>
<p>Weather:<a href="http://www.philosophicalgeek.com/wp-content/uploads/2009/02/answers-ie8-2.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="answers_ie8_2" border="0" alt="answers_ie8_2" src="http://www.philosophicalgeek.com/wp-content/uploads/2009/02/answers-ie8-2-thumb.png" width="244" height="190" /></a> Solve math equations:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2009/02/answers-ie8-1.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="answers_ie8_1" border="0" alt="answers_ie8_1" src="http://www.philosophicalgeek.com/wp-content/uploads/2009/02/answers-ie8-1-thumb.png" width="244" height="106" /></a> There are a whole lot more kinds of answers. Maybe someday I’ll detail them.</p>
<h2>Live Search Suggestions for Firefox</h2>
<p>Firefox users haven’t been left out either. While there isn’t a full instant answers integration, Firefox does support search suggestions. You can <a href="https://addons.mozilla.org/en-US/firefox/addon/10434">download the plugin</a> from the Firefox plugin directory.</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2009/02/firefox-live.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="firefox_live" border="0" alt="firefox_live" src="http://www.philosophicalgeek.com/wp-content/uploads/2009/02/firefox-live-thumb.png" width="233" height="244" /></a></p>
<h2>Live Search for Windows Mobile</h2>
<p>This is something I think really needs more publicity. I have a Samsung Saga i770, which I love. One of the first things I put on it was <a href="http://www.livesearchmobile.com/">Live Search Mobile</a>.</p>
<p>First of all, this thing has had speech recognition built-in since way before Google’s similar tools.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" alt="Easy to use, and optimized for your phone" src="http://www.livesearchmobile.com/img/home_thumb_02.jpg" /></p>
<p>It can easily find directions, gas prices, movies, traffics, maps, local businesses (by categories), and general web info. I use this app all the time.</p>
<p>There is custom software you can install for both Windows Mobile and Blackberry. It will work on the web for any other mobile phone that can get on the Internet.</p>
<p>And, by the way, it supports auto-suggest as well.</p>
<p>On your phone, you can go to <a href="http://wls.live.com">wls.live.com</a> to get it.</p>
<p><strong>Related links:</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/livesearch/archive/2009/02/03/instant-answers-in-your-ie8-search-box.aspx">Instant Answers in your IE8 Search box</a> [Live Search blog] </li>
<li><a href="http://blogs.msdn.com/livesearch/archive/2009/01/29/live-search-autosuggestions-come-to-firefox.aspx">Live Search autosuggestions come to Firefox</a> [Live Search blog] </li>
<li><a href="http://www.livesearchmobile.com/">Live Search Mobile</a> site </li>
</ul>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2009/02/20/new-apps-and-features-from-live-search/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Updated CPU usage article</title>
		<link>http://www.philosophicalgeek.com/2009/02/04/updated-cpu-usage-article/</link>
		<comments>http://www.philosophicalgeek.com/2009/02/04/updated-cpu-usage-article/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 19:44:49 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/02/04/updated-cpu-usage-article/</guid>
		<description><![CDATA[I made a important changes to the CPU usage code and have updated the article to reflect it. Instead of a critical section, the code uses just the interlocked increment/decrement functions. I also updated the sample demo to use multiple threads to read the CPU usage to demonstrate the thread safety clearly.
No tag for this [...]]]></description>
			<content:encoded><![CDATA[<p>I made a important changes to the <a href="http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/">CPU usage code</a> and have updated the article to reflect it. Instead of a critical section, the code uses just the interlocked increment/decrement functions. I also updated the sample demo to use multiple threads to read the CPU usage to demonstrate the thread safety clearly.</p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2009/02/04/updated-cpu-usage-article/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to learn WPF (or anything else)</title>
		<link>http://www.philosophicalgeek.com/2009/01/29/how-to-learn-wpf-or-anything-else/</link>
		<comments>http://www.philosophicalgeek.com/2009/01/29/how-to-learn-wpf-or-anything-else/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 05:51:20 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/29/how-to-learn-wpf-or-anything-else/</guid>
		<description><![CDATA[I’ve recently been learning WPF. This is a huge topic that is uncontainable by any single book, tutorial, or web-site. The complexity and breadth of this framework is nearly oppressive, but the results are incredible. Or rather, I should say, potentially incredible.
From everything I’ve read, people who have suffered through the WPF learning curve have [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve recently been learning WPF. This is a huge topic that is uncontainable by any single book, tutorial, or web-site. The complexity and breadth of this framework is nearly oppressive, but the results are incredible. Or rather, I should say, <em>potentially</em> incredible.</p>
<p>From everything I’ve read, people who have suffered through the WPF learning curve have this to say, more or less:</p>
<blockquote><p><font style="background-color: #ffffff" color="#333333">yeah, it was really tough going for a few months. But now I can create awesome apps in a fraction of the time it would take with older technologies.</font></p>
</blockquote>
<p>So with that in mind, I really do want to learn WPF. I have a number of C# references, weighty tomes that bend my shelves, but the main book I use is <a href="http://www.amazon.com/gp/product/0596510373?ie=UTF8&amp;tag=philosophic0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596510373">Programming WPF</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=philosophic0d-20&amp;l=as2&amp;o=1&amp;a=0596510373" width="1" border="0" />by Chris Sells and Ian Griffiths. I really like this book—it goes in deep. However, I realized that reading through it cover to cover and doing all the sample apps wasn’t going to work—it gets boring, no matter how good the book is. So here is my recommendation on how to learn WPF (and it probably applies to any programming technology):</p>
<ol>
<li>Start reading the book, do the code, type stuff in, copy it, tweak it. Do this for as long as you can.</li>
<li>Once step 1 becomes boring, <strong>STOP</strong>. It is not productive to force yourself through the whole thing like this.</li>
<li>Find a sample project in your target technology. I used <a href="http://www.vertigo.com/familyshow.aspx">Family.Show</a>. There are plenty out there.</li>
<li>Think of a project YOU find interesting that would be good in [WPF|other]. Start doing this. Even if you don’t know where to start at all. </li>
<li>While getting started, every step will be a challenge. Figure it out step-by-step, going back to the book and online resources.</li>
</ol>
<p>You might be tempted to skip steps 1-2. I think this is a bad idea. You need at least some foundational understanding. Only when you can’t take it any more and you’re in danger of quitting, move on.</p>
<p>This has worked well for me in learning WPF. I decided to implement a game (if it ever gets into a polished state, I’ll share it).</p>
<p>Don’t underestimate the challenges in step 4, though. I had to think about how to even start, going back to the book numerous times, reading large sections. I looked up articles online about patterns and WPF, user controls, and more. Many seemingly-small steps in just displaying windows took hours to figure out. Figuring out data binding (<em>really</em> figuring it out in the context of my app) took hours. The point of doing your own project isn’t because it’s easier than following the book—it’s because it’s fun and you have more motivation to learn.</p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2009/01/29/how-to-learn-wpf-or-anything-else/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Determine CPU usage of current process (C++ and C#)</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/</link>
		<comments>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 18:31:34 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/</guid>
		<description><![CDATA[Updated 2/4/2009: I changed the implementation of these classes from the original:

Instead of a critical section, InterlockedIncrement/Decrement is used.
The sample driver program now demos using multiple threads using the CpuUsage class to show thread safety.

Download the C++ and C# projects that accompany this article.
Just to make it clear, there is no API called GetProcessCpuPercentage(). To [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Updated 2/4/2009: </strong>I changed the implementation of these classes from the original:</em></p>
<ul>
<li><em>Instead of a critical section, InterlockedIncrement/Decrement is used.</em></li>
<li><em>The sample driver program now demos using multiple threads using the CpuUsage class to show thread safety.</em></li>
</ul>
<p><a href="http://www.philosophicalgeek.com/downloads/CpuUsage.zip">Download</a> the C++ and C# projects that accompany this article.</p>
<p>Just to make it clear, there is no API called GetProcessCpuPercentage(). To find out the percentage, we can use some other, real APIs and do some calculations. Before getting to the equation and code, let’s discuss the different types of time available.</p>
<p>There are four types of time:</p>
<ol>
<li>Wall time – The actual, real-world progression of time as measured by you on your watch. </li>
<li>Kernel time – The amount of time spent in kernel mode (protected, high-order mode of operation) </li>
<li>User time – the amount of time spent in user-mode (often by the process itself) </li>
<li>Idle time – nothing going on at all </li>
</ol>
<p>Kernel, User, and Idle sum to total time, which is approximately wall-time.</p>
<p>Each process spends some time in kernel mode and some time in user mode. We just need to compare the time spent by a process to the time spent by all processes on the computer, since the last time we made such a measurement. It is important to note that we do NOT take into account the idle time.</p>
<p>Thus, the equation is</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2009/01/cpupercentageequation.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="CpuPercentageEquation" border="0" alt="CpuPercentageEquation" src="http://www.philosophicalgeek.com/wp-content/uploads/2009/01/cpupercentageequation-thumb.png" width="240" height="32" /></a></p>
<p>There are two APIs that are useful:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms683223(VS.85).aspx">GetProcessTimes</a> – Get times for a specific process </li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms724400(VS.85).aspx">GetSystemTimes</a> – Get total times for the entire system (all CPUs) </li>
</ul>
<p>The times reported are absolute, so what we are actually interested is in the difference between the current times and those from a previous run.</p>
<p>Armed with this information, we can calculate the CPU usage for the current process (or any arbitrary process, for that matter).</p>
<p>Let’s do it first in C++ to demonstrate usage of the APIs.</p>
<h3>CPU Usage Percentage in C++</h3>
<p>Here&#8217;s the header file:</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> <span style="color: #cc6633">#pragma</span> once</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> #include &lt;windows.h&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> <span style="color: #0000ff">class</span> CpuUsage</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> <span style="color: #0000ff">public</span>:</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span>     CpuUsage(<span style="color: #0000ff">void</span>);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span>     </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">short</span>  GetUsage();</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span> <span style="color: #0000ff">private</span>:</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span>     ULONGLONG SubtractTimes(<span style="color: #0000ff">const</span> FILETIME&amp; ftA, <span style="color: #0000ff">const</span> FILETIME&amp; ftB);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span>     <span style="color: #0000ff">bool</span> EnoughTimePassed();</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span>     inline <span style="color: #0000ff">bool</span> IsFirstRun() <span style="color: #0000ff">const</span> { <span style="color: #0000ff">return</span> (m_dwLastRun == 0); }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span>     </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span>     <span style="color: #008000">//system total times</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span>     FILETIME m_ftPrevSysKernel;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span>     FILETIME m_ftPrevSysUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  18:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  19:</span>     <span style="color: #008000">//process times</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  20:</span>     FILETIME m_ftPrevProcKernel;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  21:</span>     FILETIME m_ftPrevProcUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  22:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  23:</span>     <span style="color: #0000ff">short</span> m_nCpuUsage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  24:</span>     ULONGLONG m_dwLastRun;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  25:</span>     </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  26:</span>     <span style="color: #0000ff">volatile</span> LONG m_lRunCount;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  27:</span> };</pre>
</p></div>
</div>
<p>The GetUsage() method is where the work occurs. The other methods are to help in the calculations. The <strike>critical section</strike> run count enables the code to be called in a multi-threaded environment without problems. I also prevent the code from being called more often than every 250ms. Here is the complete implementation:</p>
<p>&#160;</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> #include <span style="color: #006080">&quot;StdAfx.h&quot;</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> #include &lt;windows.h&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span> #include <span style="color: #006080">&quot;CpuUsage.h&quot;</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span> CpuUsage::CpuUsage(<span style="color: #0000ff">void</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> :m_nCpuUsage(-1)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span> ,m_dwLastRun(0)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span> ,m_lRunCount(0)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span>     ZeroMemory(&amp;m_ftPrevSysKernel, <span style="color: #0000ff">sizeof</span>(FILETIME));</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span>     ZeroMemory(&amp;m_ftPrevSysUser, <span style="color: #0000ff">sizeof</span>(FILETIME));</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span>     ZeroMemory(&amp;m_ftPrevProcKernel, <span style="color: #0000ff">sizeof</span>(FILETIME));</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span>     ZeroMemory(&amp;m_ftPrevProcUser, <span style="color: #0000ff">sizeof</span>(FILETIME));</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span> }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  18:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  19:</span> <span style="color: #008000">/**********************************************</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  20:</span> <span style="color: #008000">* CpuUsage::GetUsage</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  21:</span> <span style="color: #008000">* returns the percent of the CPU that this process</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  22:</span> <span style="color: #008000">* has used since the last time the method was called.</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  23:</span> <span style="color: #008000">* If there is not enough information, -1 is returned.</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  24:</span> <span style="color: #008000">* If the method is recalled to quickly, the previous value</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  25:</span> <span style="color: #008000">* is returned.</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  26:</span> <span style="color: #008000">***********************************************/</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  27:</span> <span style="color: #0000ff">short</span> CpuUsage::GetUsage()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  28:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  29:</span>     <span style="color: #008000">//create a local copy to protect against race conditions in setting the </span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  30:</span>     <span style="color: #008000">//member variable</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  31:</span>     <span style="color: #0000ff">short</span> nCpuCopy = m_nCpuUsage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  32:</span>     <span style="color: #0000ff">if</span> (::InterlockedIncrement(&amp;m_lRunCount) == 1)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  33:</span>     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  34:</span>         <span style="color: #008000">/*</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  35:</span> <span style="color: #008000">        If this is called too often, the measurement itself will greatly </span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  36:</span> <span style="color: #008000">        affect the results.</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  37:</span> <span style="color: #008000">        */</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  38:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  39:</span>         <span style="color: #0000ff">if</span> (!EnoughTimePassed())</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  40:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  41:</span>             ::InterlockedDecrement(&amp;m_lRunCount);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  42:</span>             <span style="color: #0000ff">return</span> nCpuCopy;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  43:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  44:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  45:</span>         FILETIME ftSysIdle, ftSysKernel, ftSysUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  46:</span>         FILETIME ftProcCreation, ftProcExit, ftProcKernel, ftProcUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  47:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  48:</span>         <span style="color: #0000ff">if</span> (!GetSystemTimes(&amp;ftSysIdle, &amp;ftSysKernel, &amp;ftSysUser) ||</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  49:</span>             !GetProcessTimes(GetCurrentProcess(), &amp;ftProcCreation, </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  50:</span>                 &amp;ftProcExit, &amp;ftProcKernel, &amp;ftProcUser))</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  51:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  52:</span>             ::InterlockedDecrement(&amp;m_lRunCount);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  53:</span>             <span style="color: #0000ff">return</span> nCpuCopy;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  54:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  55:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  56:</span>         <span style="color: #0000ff">if</span> (!IsFirstRun())</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  57:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  58:</span>             <span style="color: #008000">/*</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  59:</span> <span style="color: #008000">            CPU usage is calculated by getting the total amount of time </span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  60:</span> <span style="color: #008000">            the system has operated since the last measurement </span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  61:</span> <span style="color: #008000">            (made up of kernel + user) and the total</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  62:</span> <span style="color: #008000">            amount of time the process has run (kernel + user).</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  63:</span> <span style="color: #008000">            */</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  64:</span>             ULONGLONG ftSysKernelDiff = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  65:</span>                 SubtractTimes(ftSysKernel, m_ftPrevSysKernel);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  66:</span>             ULONGLONG ftSysUserDiff = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  67:</span>                 SubtractTimes(ftSysUser, m_ftPrevSysUser);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  68:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  69:</span>             ULONGLONG ftProcKernelDiff = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  70:</span>                 SubtractTimes(ftProcKernel, m_ftPrevProcKernel);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  71:</span>             ULONGLONG ftProcUserDiff = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  72:</span>             SubtractTimes(ftProcUser, m_ftPrevProcUser);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  73:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  74:</span>             ULONGLONG nTotalSys =  ftSysKernelDiff + ftSysUserDiff;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  75:</span>             ULONGLONG nTotalProc = ftProcKernelDiff + ftProcUserDiff;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  76:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  77:</span>             <span style="color: #0000ff">if</span> (nTotalSys &gt; 0)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  78:</span>             {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  79:</span>                 m_nCpuUsage = (<span style="color: #0000ff">short</span>)((100.0 * nTotalProc) / nTotalSys);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  80:</span>             }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  81:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  82:</span>         </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  83:</span>         m_ftPrevSysKernel = ftSysKernel;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  84:</span>         m_ftPrevSysUser = ftSysUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  85:</span>         m_ftPrevProcKernel = ftProcKernel;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  86:</span>         m_ftPrevProcUser = ftProcUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  87:</span>         </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  88:</span>         m_dwLastRun = GetTickCount64();</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  89:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  90:</span>         nCpuCopy = m_nCpuUsage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  91:</span>     }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  92:</span>     </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  93:</span>     ::InterlockedDecrement(&amp;m_lRunCount);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  94:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  95:</span>     <span style="color: #0000ff">return</span> nCpuCopy;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  96:</span> }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  97:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  98:</span> ULONGLONG CpuUsage::SubtractTimes(<span style="color: #0000ff">const</span> FILETIME&amp; ftA, <span style="color: #0000ff">const</span> FILETIME&amp; ftB)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  99:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 100:</span>     LARGE_INTEGER a, b;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 101:</span>     a.LowPart = ftA.dwLowDateTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 102:</span>     a.HighPart = ftA.dwHighDateTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 103:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 104:</span>     b.LowPart = ftB.dwLowDateTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 105:</span>     b.HighPart = ftB.dwHighDateTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 106:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 107:</span>     <span style="color: #0000ff">return</span> a.QuadPart - b.QuadPart;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 108:</span> }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 109:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 110:</span> <span style="color: #0000ff">bool</span> CpuUsage::EnoughTimePassed()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 111:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 112:</span>     <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> minElapsedMS = 250;<span style="color: #008000">//milliseconds</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 113:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 114:</span>     ULONGLONG dwCurrentTickCount = GetTickCount64();</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 115:</span>     <span style="color: #0000ff">return</span> (dwCurrentTickCount - m_dwLastRun) &gt; minElapsedMS; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 116:</span> }</pre>
</p></div>
</div>
<p>In order to test this, here is a simple program that starts two threads that run an infinite loop, eating the processor. On a dual-core system, this process will take roughly 85-95% of the CPU. I also start two threads to access the usage object and poll the CPU usage in order to demonstrate the thread safety of the object.</p>
<p>&#160;</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> <span style="color: #008000">// CpuUsageCpp.cpp : Defines the entry point for the console application.</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> <span style="color: #008000">//</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> #include <span style="color: #006080">&quot;stdafx.h&quot;</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span> #include &lt;windows.h&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> #include <span style="color: #006080">&quot;CpuUsage.h&quot;</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span> DWORD WINAPI EatItThreadProc(LPVOID lpParam);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span> DWORD WINAPI WatchItThreadProc(LPVOID lpParam);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span> CpuUsage usage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span> <span style="color: #0000ff">int</span> _tmain(<span style="color: #0000ff">int</span> argc, _TCHAR* argv[])</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span>     <span style="color: #008000">//start threads to eat the processor</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span>     CreateThread(NULL, 0, EatItThreadProc, NULL, 0, NULL);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span>     CreateThread(NULL, 0, EatItThreadProc, NULL, 0, NULL);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  18:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  19:</span>     <span style="color: #008000">//start threads to watch the processor (to test thread-safety)</span></pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  20:</span>     CreateThread(NULL, 0, WatchItThreadProc, NULL, 0, NULL);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  21:</span>     CreateThread(NULL, 0, WatchItThreadProc, NULL, 0, NULL);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  22:</span>     </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  23:</span>     <span style="color: #0000ff">while</span> (<span style="color: #0000ff">true</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  24:</span>     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  25:</span>         Sleep(1000);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  26:</span>     }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  27:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  28:</span>     <span style="color: #0000ff">return</span> 0;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  29:</span> }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  30:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  31:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  32:</span> DWORD WINAPI WatchItThreadProc(LPVOID lpParam)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  33:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  34:</span>     <span style="color: #0000ff">while</span> (<span style="color: #0000ff">true</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  35:</span>     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  36:</span>         <span style="color: #0000ff">short</span> cpuUsage = usage.GetUsage();</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  37:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  38:</span>         printf(<span style="color: #006080">&quot;Thread id %d: %d%% cpu usage\n&quot;</span>, ::GetCurrentThreadId(), cpuUsage);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  39:</span>         Sleep(1000);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  40:</span>     }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  41:</span> }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  42:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  43:</span> DWORD WINAPI EatItThreadProc(LPVOID lpParam)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  44:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  45:</span>     ULONGLONG accum = 0;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  46:</span>     <span style="color: #0000ff">while</span> (<span style="color: #0000ff">true</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  47:</span>     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  48:</span>         accum++;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  49:</span>     }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  50:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  51:</span>     printf(<span style="color: #006080">&quot;%64d\n&quot;</span>, accum);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  52:</span> }</pre>
</p></div>
</div>
<h3>C# Version</h3>
<p>In C#, The <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx">System.Diagnostics.Process</a> can give us the time information for a specific process. However, we still need the Win32 API call for getting the total system times (GetSystemTimes). The Process class reports times in <a href="http://msdn.microsoft.com/en-us/library/system.timespan.aspx">TimeSpans</a>, not <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comtypes.filetime.aspx">FILETIME</a>, so our class is modified accordingly.</p>
<p>&#160;</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> <span style="color: #0000ff">using</span> System;<span style="color: #0000ff">using</span> System.Collections.Generic;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> <span style="color: #0000ff">using</span> System.Linq;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span> <span style="color: #0000ff">using</span> System.Text;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> <span style="color: #0000ff">using</span> System.Runtime.InteropServices;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span> <span style="color: #0000ff">using</span> ComTypes = System.Runtime.InteropServices.ComTypes;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> <span style="color: #0000ff">using</span> System.Threading;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span> <span style="color: #0000ff">using</span> System.Diagnostics;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span> <span style="color: #0000ff">namespace</span> CpuUsageCs</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span>     <span style="color: #0000ff">class</span> CpuUsage</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span>     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span>         [DllImport(<span style="color: #006080">&quot;kernel32.dll&quot;</span>, SetLastError = <span style="color: #0000ff">true</span>)]</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span>         <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> <span style="color: #0000ff">bool</span> GetSystemTimes(</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span>                     <span style="color: #0000ff">out</span> ComTypes.FILETIME lpIdleTime,</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span>                     <span style="color: #0000ff">out</span> ComTypes.FILETIME lpKernelTime,</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span>                     <span style="color: #0000ff">out</span> ComTypes.FILETIME lpUserTime</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  18:</span>                     );</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  19:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  20:</span>         ComTypes.FILETIME _prevSysKernel;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  21:</span>         ComTypes.FILETIME _prevSysUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  22:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  23:</span>         TimeSpan _prevProcTotal;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  24:</span>         </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  25:</span>         Int16 _cpuUsage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  26:</span>         DateTime _lastRun;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  27:</span>         <span style="color: #0000ff">long</span> _runCount;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  28:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  29:</span>         <span style="color: #0000ff">public</span> CpuUsage()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  30:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  31:</span>             _cpuUsage = -1;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  32:</span>             _lastRun = DateTime.MinValue;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  33:</span>             _prevSysUser.dwHighDateTime = _prevSysUser.dwLowDateTime = 0;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  34:</span>             _prevSysKernel.dwHighDateTime = _prevSysKernel.dwLowDateTime = 0;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  35:</span>             _prevProcTotal = TimeSpan.MinValue;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  36:</span>             _runCount = 0;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  37:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  38:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  39:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">short</span> GetUsage()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  40:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  41:</span>             <span style="color: #0000ff">short</span> cpuCopy = _cpuUsage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  42:</span>             <span style="color: #0000ff">if</span> (Interlocked.Increment(<span style="color: #0000ff">ref</span> _runCount) == 1)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  43:</span>             {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  44:</span>                 <span style="color: #0000ff">if</span> (!EnoughTimePassed)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  45:</span>                 {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  46:</span>                     Interlocked.Decrement(<span style="color: #0000ff">ref</span> _runCount);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  47:</span>                     <span style="color: #0000ff">return</span> cpuCopy;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  48:</span>                 }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  49:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  50:</span>                 ComTypes.FILETIME sysIdle, sysKernel, sysUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  51:</span>                 TimeSpan procTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  52:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  53:</span>                 Process process = Process.GetCurrentProcess();</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  54:</span>                 procTime = process.TotalProcessorTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  55:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  56:</span>                 <span style="color: #0000ff">if</span> (!GetSystemTimes(<span style="color: #0000ff">out</span> sysIdle, <span style="color: #0000ff">out</span> sysKernel, <span style="color: #0000ff">out</span> sysUser))</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  57:</span>                 {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  58:</span>                     Interlocked.Decrement(<span style="color: #0000ff">ref</span> _runCount);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  59:</span>                     <span style="color: #0000ff">return</span> cpuCopy;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  60:</span>                 }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  61:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  62:</span>                 <span style="color: #0000ff">if</span> (!IsFirstRun)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  63:</span>                 {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  64:</span>                     UInt64 sysKernelDiff = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  65:</span>                         SubtractTimes(sysKernel, _prevSysKernel);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  66:</span>                     UInt64 sysUserDiff = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  67:</span>                         SubtractTimes(sysUser, _prevSysUser);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  68:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  69:</span>                     UInt64 sysTotal = sysKernelDiff + sysUserDiff;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  70:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  71:</span>                     Int64 procTotal = procTime.Ticks - _prevProcTotal.Ticks;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  72:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  73:</span>                     <span style="color: #0000ff">if</span> (sysTotal &gt; 0)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  74:</span>                     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  75:</span>                         _cpuUsage = (<span style="color: #0000ff">short</span>)((100.0 * procTotal) / sysTotal);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  76:</span>                     }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  77:</span>                 }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  78:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  79:</span>                 _prevProcTotal = procTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  80:</span>                 _prevSysKernel = sysKernel;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  81:</span>                 _prevSysUser = sysUser;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  82:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  83:</span>                 _lastRun = DateTime.Now;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  84:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  85:</span>                 cpuCopy = _cpuUsage;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  86:</span>             }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  87:</span>             Interlocked.Decrement(<span style="color: #0000ff">ref</span> _runCount);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  88:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  89:</span>             <span style="color: #0000ff">return</span> cpuCopy;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  90:</span>                 </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  91:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  92:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  93:</span>         <span style="color: #0000ff">private</span> UInt64 SubtractTimes(ComTypes.FILETIME a, ComTypes.FILETIME b)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  94:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  95:</span>             UInt64 aInt = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  96:</span>             ((UInt64)(a.dwHighDateTime &lt;&lt; 32)) | (UInt64)a.dwLowDateTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  97:</span>             UInt64 bInt = </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  98:</span>             ((UInt64)(b.dwHighDateTime &lt;&lt; 32)) | (UInt64)b.dwLowDateTime;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  99:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 100:</span>             <span style="color: #0000ff">return</span> aInt - bInt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 101:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 102:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 103:</span>         <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> EnoughTimePassed</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 104:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 105:</span>             get</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 106:</span>             {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 107:</span>                 <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> minimumElapsedMS = 250;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 108:</span>                 TimeSpan sinceLast = DateTime.Now - _lastRun;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 109:</span>                 <span style="color: #0000ff">return</span> sinceLast.TotalMilliseconds &gt; minimumElapsedMS;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 110:</span>             }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 111:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 112:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 113:</span>         <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> IsFirstRun</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 114:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 115:</span>             get</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 116:</span>             {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 117:</span>                 <span style="color: #0000ff">return</span> (_lastRun == DateTime.MinValue);</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 118:</span>             }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 119:</span>         }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 120:</span>     }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060"> 121:</span> }</pre>
</p></div>
</div>
<p>These classes can now be used wherever you need to monitor the CPU usage of a process.</p>
<p>Notice any improvements to be made? Leave a comment.</p>
<p><a href="http://www.philosophicalgeek.com/downloads/CpuUsage.zip">Download</a> C++ and C# projects</p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An easy stack layout panel for WinForms</title>
		<link>http://www.philosophicalgeek.com/2008/12/12/an-easy-stack-layout-panel-for-winforms/</link>
		<comments>http://www.philosophicalgeek.com/2008/12/12/an-easy-stack-layout-panel-for-winforms/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 04:52:51 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[.net]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/12/12/an-easy-stack-layout-panel-for-winforms/</guid>
		<description><![CDATA[This is a simple, but useful tip. Users of WPF are spoiled. They have all sorts of layout options. Those of us still working in WinForms have FlowLayoutPanel and TableLayoutPanel. That’s it. WPF has those and more.
For my current project, I needed a panel to layout controls vertically. The TableLayoutPanel can be awkward to work [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple, but useful tip. Users of WPF are spoiled. They have all sorts of layout options. Those of us still working in WinForms have <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.aspx">FlowLayoutPanel</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.aspx">TableLayoutPanel</a>. That’s it. WPF has those <a href="http://msdn.microsoft.com/en-us/library/ms745058.aspx#LayoutSystem_PanelsCustom">and more</a>.</p>
<p>For my current project, I needed a panel to layout controls vertically. The TableLayoutPanel can be awkward to work with, at least for what I need it to. At first glance, the FlowLayoutPanel looks it won’t work, since it produces something like this:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/flowlayouttable-1.png"><img title="FlowLayoutTable_1" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="397" alt="FlowLayoutTable_1" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/flowlayouttable-1-thumb.png" width="361" border="0" /></a> </p>
<p>That’s with changing the FlowDirection to TopDown and putting AutoScroll to true.</p>
<p>But what I want is this:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/image.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/image-thumb.png" width="396" border="0" /></a> </p>
<p>To achieve this layout, merely set all the following properties on a FlowLayoutPanel:</p>
<ul>
<li>AutoScroll = True</li>
<li>FlowDirection = TopDown</li>
<li>WrapContents = False</li>
</ul>
<p>et voilà, Instant stack panel.</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/net/" title=".net" rel="tag">.net</a>, <a href="http://www.philosophicalgeek.com/tag/c/" title="C#" rel="tag">C#</a>, <a href="http://www.philosophicalgeek.com/tag/code/" title="Code" rel="tag">Code</a>, <a href="http://www.philosophicalgeek.com/tag/programming/" title="programming" rel="tag">programming</a>, <a href="http://www.philosophicalgeek.com/tag/tips/" title="Tips" rel="tag">Tips</a>, <a href="http://www.philosophicalgeek.com/tag/windows/" title="windows" rel="tag">windows</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/12/12/an-easy-stack-layout-panel-for-winforms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Malware Detection in Live Search and Webmaster Tools</title>
		<link>http://www.philosophicalgeek.com/2008/12/04/malware-detection-in-live-search-and-webmaster-tools/</link>
		<comments>http://www.philosophicalgeek.com/2008/12/04/malware-detection-in-live-search-and-webmaster-tools/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 18:30:14 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Live Search]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[jobs]]></category>

		<category><![CDATA[live search]]></category>

		<category><![CDATA[malware]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/12/04/malware-detection-in-live-search-and-webmaster-tools/</guid>
		<description><![CDATA[Live Search has recently released some great new features that I want to highlight. The first is from the Webmaster center, which is the team I was hired on.
With the new Webmaster Tools, you can now see which pages on your site are infected with malware (aka drive-by downloads). The links are clearly highlighted and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.live.com">Live Search</a> has recently released some great new features that I want to highlight. The first is from the <a href="http://webmaster.live.com">Webmaster center</a>, which is the team I was hired on.</p>
<p>With the new Webmaster Tools, you can now see which pages on your site are infected with malware (aka drive-by downloads). The links are clearly highlighted and disabled so that you won’t accidentally click on them.</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/webmaster-crawl-issues.png"><img title="webmaster_crawl_issues" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="401" alt="webmaster_crawl_issues" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/webmaster-crawl-issues-thumb.png" width="404" border="0" /></a> </p>
<p>Not only that, but you can also see what pages that your site links to are infected with malware. This is great if your site allows any user-generated content and it’s possible that some link spam has made it on.</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/webmaster-outbound-links.png"><img title="webmaster_outbound_links" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="382" alt="webmaster_outbound_links" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/webmaster-outbound-links-thumb.png" width="404" border="0" /></a> </p>
<p>In addition to these improvements in Webmaster Tools, the general Live Search engine is using the same malware detection to notify users of bad pages in the general search results. To <a href="http://search.live.com/results.aspx?q=sahajdental.com%2Fdentist.htm&amp;go=&amp;form=QBRE">see this</a>, click on the link as if to visit it and you’ll get a pop-up instead.</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/livesearch-malware.png"><img title="livesearch_malware" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="194" alt="livesearch_malware" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/12/livesearch-malware-thumb.png" width="404" border="0" /></a> </p>
<p>If you run your own site, get signed up in Webmaster Tools and make sure you’re not contributing to the malware problem. If you do find that your site has malware on it, once you’ve removed it you can request that your site be reanalyzed.</p>
<p>For more info, check out these other blogs and articles:</p>
<ul>
<li><a href="http://blogs.msdn.com/webmaster/archive/2008/11/25/live-search-webmaster-center-fall-update.aspx">Live Search Webmaster Center Fall Update</a> [Webmaster Center blog]</li>
<li><a href="http://blogs.msdn.com/livesearch/archive/2008/11/25/webmaster-tools-now-sniffing-for-malware.aspx">Webmaster tools now sniffing for malware</a> [Live Search blog]</li>
<li><a href="http://blogs.zdnet.com/security/?p=2231">Microsoft’s Live launches malware detection service for webmasters</a> [ZDNet blogs] (though the author incorrectly assumes that Live Search itself doesn’t offer this feature)</li>
<li>Link to <a href="http://search.live.com/results.aspx?q=live+search+webmaster+malware&amp;form=QBRE">search results for articles</a> about this</li>
</ul>

	Tags: <a href="http://www.philosophicalgeek.com/tag/jobs/" title="jobs" rel="tag">jobs</a>, <a href="http://www.philosophicalgeek.com/tag/live-search/" title="live search" rel="tag">live search</a>, <a href="http://www.philosophicalgeek.com/tag/malware/" title="malware" rel="tag">malware</a>, <a href="http://www.philosophicalgeek.com/tag/microsoft/" title="microsoft" rel="tag">microsoft</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/12/04/malware-detection-in-live-search-and-webmaster-tools/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NDepend: A short review</title>
		<link>http://www.philosophicalgeek.com/2008/11/29/ndepend-a-short-review/</link>
		<comments>http://www.philosophicalgeek.com/2008/11/29/ndepend-a-short-review/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 00:28:54 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Link/News]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[reviews]]></category>

		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/11/29/ndepend-a-short-review/</guid>
		<description><![CDATA[NDepend is a tool I’d heard about for years, but had yet to really dive into recently. Thanks to the good folks developing it, I was able to try out a copy and have been analyzing my own projects with it.
Here’s a brief run-down of my initial experience with it.
Installation
There is no installation file—everything is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ndepend.com/">NDepend</a> is a tool I’d heard about for years, but had yet to really dive into recently. Thanks to the good folks developing it, I was able to try out a copy and have been analyzing my own projects with it.</p>
<p>Here’s a brief run-down of my initial experience with it.</p>
<h2>Installation</h2>
<p>There is no installation file—everything is packaged into a zip. After running, I was greeted by a project selection screen, in which I created a new project and added some assemblies. <a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-mainscreen.png"><img title="NDepend main screen" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="232" alt="NDepend main screen" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-mainscreen-thumb.png" width="404" border="0" /></a> </p>
<h2>Analysis</h2>
<p>Once you have all the assemblies you want to analyze selected, you can run the analysis, which generates both an HTML report with graphics, and an interactive report that you can use to drill down into almost any detail of your code. Indeed, it’s almost overwhelming the amount of detail present in this tool.</p>
<p>One graph you see almost immediately is Abstractness Vs. Instability.</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-abstractnessvsinstability.png"><img title="Abstractness vs. Instability" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="404" alt="Abstractness vs. Instability" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-abstractnessvsinstability-thumb.png" width="404" border="0" /></a> </p>
<p>This is a good high-level overview of your entire project at the assembly level. Basically, what this means is that assemblies that are too abstract and unstable are potentially useless and should be culled, while assemblies that are concrete and stable can be hard to maintain. Instability is defined in the help docs in terms of coupling (internal and external), while abstractness is the ratio of abstract types to total types in an assembly.</p>
<p>This is followed by the dependency graph:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-dependencies.png"><img title="Dependency graph" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="124" alt="Dependency graph" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-dependencies-thumb.png" width="404" border="0" /></a> </p>
<p>After these graphics come lots of reports that dig into your code for all sorts of conditions.</p>
<p>For example, the first one in my report was “Quick summary of methods to refactor&quot;.” That seems pretty vague, until you learn how they determine this. All the reports in NDepend are built off of a SQL-like query language called CQL (Code Query Language). The syntax for this is extremely easy. The query and result for this report are:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-refactormethods.png"><img title="NDepend_RefactorMethods" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="234" alt="NDepend_RefactorMethods" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-refactormethods-thumb.png" width="404" border="0" /></a> </p>
<p>With very little work on my part, I instantly have a checklist of items I need to look at to improve code quality and maintainability.</p>
<p>There are tons of other reports: methods that are too complex, methods that are poorly commented, have too many parameters, to many local variables, or classes with too many methods, etc. And of course, you can create your own (which I demonstrate below).</p>
<h2>Interactive Visualization</h2>
<p>All of these reports are put into the HTML report. But as I said, you can use the interactive visualizer to drill down further into your code.</p>
<p>The first thing you’re likely to see is a group of boxes looking like this:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-metrics.png"><img title="NDepend_Metrics" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="174" alt="NDepend_Metrics" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-metrics-thumb.png" width="404" border="0" /></a> </p>
<p>These boxes show the relative sizes of your code from the assembly level down to the methods. Holding the mouse over a box will bring up more information about the method. You can also change the metric you’re measuring by—say to <a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatic complexity</a>.</p>
<p>Another view, perhaps the most useful of all is the CQL Queries view. In this, you can see the results from all of hundreds of code queries, as well as create your own. For instance, I can see all the types with poor cohesion in my codebase:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-cohesion.png"><img title="NDepend_Cohesion" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="327" alt="NDepend_Cohesion" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-cohesion-thumb.png" width="404" border="0" /></a> </p>
<p>In this view, the CQL queries are selected in the bottom-right, and the results show up on the left. The metrics view highlights the affected methods.</p>
<h2>Creating a query</h2>
<p>Early in the development of my project, I named quite a few classes starting with a LB prefix. I’ve changed some of them, but I think there are still a few lying around and I want to change them as well. So I’ll create CQL query to return all the types that begin with “LB.”</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #008000">// &lt;Name&gt;Types beginning with LB&lt;/Name&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> WARN IF Count &gt; 0 IN SELECT TYPES WHERE </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>  NameLike <span style="color: #006080">&quot;LB&quot;</span> AND     </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>  !IsGeneratedByCompiler AND </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>  !IsInFrameworkAssembly     </pre>
</p></div>
</div>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-lb.png"><img title="NDepend_LB" style="border-right: 0px; border-top: 0px; display: inline; margin-left: 0px; border-left: 0px; margin-right: 0px; border-bottom: 0px" height="244" alt="NDepend_LB" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-lb-thumb.png" width="128" align="right" border="0" /></a> That’s it! You can see the results to the right. It’s ridiculously easy to create your own queries to examine nearly any aspect of your code. And that’s if the hundreds of included queries don’t do it for you. In many ways, the queries are similar to the analysis <a href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx">FxCop</a> does, but I think CQL seems generally more powerful (while lacking some of the cool things FxCop has).</p>
<p>&#160;</p>
<h2>VS and Reflector Add-ins</h2>
<p>NDepend has a couple of extras that enable integration of Visual Studio (2005 and 2008) and NDepend and Reflector. When you right-click on an item in VS, you will have some additional options available:</p>
<p><a href="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-vsplugin1.png"><img title="NDepend_VSPlugin1" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="NDepend_VSPlugin1" src="http://www.philosophicalgeek.com/wp-content/uploads/2008/11/ndepend-vsplugin1-thumb.png" width="415" border="0" /></a> </p>
<p>Clicking on the submenu gives you options to directly run queries in NDepend. Very cool stuff.</p>
<h2>Summary and where to get more info</h2>
<p>If you are at all interested in code metrics, and how good your code is behaving, how maintainable it is, you need this tool. It’s now going to be a standard part of my toolbox for evaluating the quality of my code and what parts need attention.</p>
<p>If you’re using NDepend for personal and non-commercial reasons, you can download it for free. It doesn’t have <a href="http://www.ndepend.com/Editions.aspx">all the features</a>, but it has more than enough. Professional use does require a license.</p>
<p>One of the things I was particularly impressed with was the amount of <a href="http://www.ndepend.com/GettingStarted.aspx">help content</a> available. There are tons of tutorials for every part of the program. </p>
<p>I’m going to keep playing with this and I’m sure I’ll mention some more things as I discover them. For now, NDepend is very cool—it’s actually fun to play with, and it gives you good information for what to work on.</p>
<p>Links:</p>
<ul>
<li><a href="http://www.ndepend.com/">NDepend homepage</a></li>
<li><a href="http://www.hanselman.com/blog/content/binary/NDepend%20metrics%20placemats%201.1.pdf">NDepend metrics explanation</a></li>
</ul>

	Tags: <a href="http://www.philosophicalgeek.com/tag/code/" title="Code" rel="tag">Code</a>, <a href="http://www.philosophicalgeek.com/tag/programming/" title="programming" rel="tag">programming</a>, <a href="http://www.philosophicalgeek.com/tag/reviews/" title="reviews" rel="tag">reviews</a>, <a href="http://www.philosophicalgeek.com/tag/software/" title="software" rel="tag">software</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/11/29/ndepend-a-short-review/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Better Find In Files results in Visual Studio</title>
		<link>http://www.philosophicalgeek.com/2008/11/25/better-find-in-files-results-in-visual-studio/</link>
		<comments>http://www.philosophicalgeek.com/2008/11/25/better-find-in-files-results-in-visual-studio/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 16:03:06 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/11/25/better-find-in-files-results-in-visual-studio/</guid>
		<description><![CDATA[Sara Ford has an awesome tip for Visual Studio on how to customize the formatting of search results.

	Tags: Tips, visual studio
]]></description>
			<content:encoded><![CDATA[<p>Sara Ford has <a href="http://blogs.msdn.com/saraford/archive/2008/11/24/did-you-know-you-can-customize-how-search-results-are-displayed-in-the-find-results-window-363.aspx">an awesome tip</a> for Visual Studio on how to customize the formatting of search results.</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/tips/" title="Tips" rel="tag">Tips</a>, <a href="http://www.philosophicalgeek.com/tag/visual-studio/" title="visual studio" rel="tag">visual studio</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/11/25/better-find-in-files-results-in-visual-studio/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Girl from Mars &#8211; Magneta Lane</title>
		<link>http://www.philosophicalgeek.com/2008/11/22/girl-from-mars-magneta-lane/</link>
		<comments>http://www.philosophicalgeek.com/2008/11/22/girl-from-mars-magneta-lane/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 02:06:14 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Music, Film, Theater]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[music]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/11/22/girl-from-mars-magneta-lane/</guid>
		<description><![CDATA[



I first saw this video at the Microsoft Company Meeting 2008, and looked for the song everywhere, but couldn’t find the Magneta Lane version. They recorded it just for Microsoft. Nevertheless, the original Ash version is great too, so get that in the meantime. 
Magneta&#8217; Lane’s MySpace page does mention the song, and maybe a [...]]]></description>
			<content:encoded><![CDATA[</p>
<div class="wlWriterEditableSmartContent" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:c380febe-737c-45e2-866b-888f1347a792" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<div><embed src="http://images.video.msn.com/flash/soapbox1_1.swf" quality="high" width="432" height="364" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://macromedia.com/go/getflashplayer" flashvars="c=v&#038;v=0982c703-4208-42e1-b021-ac5a95ab34f5&#038;from=writer&#038;mkt=en-US"></embed></div>
</div>
<p>I first saw this video at the Microsoft Company Meeting 2008, and looked for the song everywhere, but couldn’t find the Magneta Lane version. They recorded it just for Microsoft. Nevertheless, the <a href="http://www.amazon.com/gp/product/B000002N5Q?ie=UTF8&amp;tag=philosophic0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B000002N5Q">original Ash version</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=philosophic0d-20&amp;l=as2&amp;o=1&amp;a=B000002N5Q" width="1" border="0" /> is great too, so get that in the meantime. </p>
<p>Magneta&#8217; Lane’s <a href="http://www.myspace.com/kissingiseasy">MySpace page</a> does <a href="http://blog.myspace.com/index.cfm?fuseaction=blog.view&amp;friendID=137054083&amp;blogID=422447907">mention the song</a>, and maybe a release is on the way.</p>
<p><strong>Update</strong>: Forgot the music video from Ash. I like it.</p>
<p> <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/2MZwmy0OnPo&amp;hl=en&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/2MZwmy0OnPo&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/microsoft/" title="microsoft" rel="tag">microsoft</a>, <a href="http://www.philosophicalgeek.com/tag/music/" title="music" rel="tag">music</a>, <a href="http://www.philosophicalgeek.com/tag/windows/" title="windows" rel="tag">windows</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/11/22/girl-from-mars-magneta-lane/feed/</wfw:commentRss>
		</item>
		<item>
		<title>On the importance of ignoring your problems</title>
		<link>http://www.philosophicalgeek.com/2008/11/20/on-the-importance-of-ignoring-your-problems/</link>
		<comments>http://www.philosophicalgeek.com/2008/11/20/on-the-importance-of-ignoring-your-problems/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 01:34:30 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/11/20/on-the-importance-of-ignoring-your-problems/</guid>
		<description><![CDATA[I’ve been having a great time at Microsoft over the last couple of months, but the ramp to full productivity is very steep. Recently, I’ve been working on an important improvement to some monitoring software, which requires a fairly good understanding of part of the system. It can be a little overwhelming trying to design [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been having a great time at Microsoft over the last couple of months, but the ramp to full productivity is very steep. Recently, I’ve been working on an important improvement to some monitoring software, which requires a fairly good understanding of part of the system. It can be a little overwhelming trying to design something to handle all the nuances involved. Add to that the time crunch, and things get a little interesting. Last night, I ran into a little wall where I was uncertain about how to proceed. This kind of situation is always a little precarious. I was worried because today and tomorrow I have full-day training and won’t be able to dedicate a lot of time to solving this problem.</p>
<p>Half way through the training, while discussing something tangentially related to my problems, I realized the technical solution to the specific issue I was facing.</p>
<p>Sometimes you just need to ignore the problem for a while, and come back to it from a different angle.</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/programming/" title="programming" rel="tag">programming</a>, <a href="http://www.philosophicalgeek.com/tag/tips/" title="Tips" rel="tag">Tips</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/11/20/on-the-importance-of-ignoring-your-problems/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Consequences of a Star Trek-like computer</title>
		<link>http://www.philosophicalgeek.com/2008/11/17/consequences-of-a-star-trek-like-computer/</link>
		<comments>http://www.philosophicalgeek.com/2008/11/17/consequences-of-a-star-trek-like-computer/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 04:54:28 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[A Better Future]]></category>

		<category><![CDATA[Thoughts On Tech and More]]></category>

		<category><![CDATA[AI]]></category>

		<category><![CDATA[computer]]></category>

		<category><![CDATA[privacy]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[star trek]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/11/17/consequences-of-a-star-trek-like-computer/</guid>
		<description><![CDATA[Star Trek, along with other science fiction futures, has given us many things, apart from a vision of humanity that is hopefully a little better than we prove to be, but also a taste of what technology can be like when it is integrated so fully into people’s lives that it’s nearly taken for granted.
The [...]]]></description>
			<content:encoded><![CDATA[<p>Star Trek, along with other science fiction futures, has given us many things, apart from a vision of humanity that is hopefully a little better than we prove to be, but also a taste of what technology can be like when it is integrated so fully into people’s lives that it’s nearly taken for granted.</p>
<p>The computer on the Enterprise is an interesting entity to think about. A crew member can ask it just about any question and it can give the desired answer. It doesn’t matter if the question is slightly vague, or depends on prior knowledge of the conversation. What phenomenal power! How does it work?</p>
<p>I can think of only two possibilities:</p>
<ol>
<li>It can read their minds </li>
<li>It has been paying attention to their conversation, and thus understands the context. </li>
</ol>
<p>Not discounting the possibility of the first scenario, I want to think about the second. </p>
<p><strong>Context</strong></p>
<p>How much understanding of our immediate environment is due to context? When analyzing a situation we have at our disposal our</p>
<ol>
<li>Experience </li>
<li>Book knowledge </li>
<li>Logical analysis/intuition (I include them in the same since intuition could theoretically be a subconscious logical process, colored with experience—I don’t know if I believe that, but it’s not important) </li>
</ol>
<p>Now take away experience. How would you fare when confronted with new situations (Which, by definition, are <em>all</em> situations)?</p>
<p>Most of us, I think, would understandably quail under the rigor of thought required to get through such an ordeal. If you believe otherwise, make the situation extreme—flying a plane, or leading a squad into war. No amount of knowledge or rational thought will help here—you need the benefit of hard-core training: experience&#8211;context.</p>
<p>Do this exercise: describe to someone what salt tastes like. </p>
<p>On the other hand, saying “It’s too salty.” immediately conveys exactly what you mean, based on shared context, mutual experience.</p>
<p>There is an enormous gap between where our computer systems are now, versus what is perhaps the holy grail of foreseeable technology, the computer on the Enterprise—an all-seeing, all-knowing, conversant entity. It’s like Wikipedia, but to a depth of knowledge unheard of on any web site today, all cross-referenced and Searchable.</p>
<p>Wikipedia is a decent (I won’t say great) source of much knowledge, but it’s hardly definitive, or all-encompassing. Also, it’s just facts. It’s not calculation or interpretation. It does not advise or synthesize.</p>
<p>In Star Trek, when&#160; a crewmember asks questions, they can be these fact-based, context-free questions that require simple look-ups to respond with. But often, there is a series of questions, with dialogue in-between, all related to a certain topic. Each query does not contain the total information required to retrieve a response. Rather, the computer has tracked the context and maintained an accurate representation of the conversation thus far. In essence, the computer is participating in the conversation fully.</p>
<p>An idea of what context means is demonstrated by this simple list of questions. Just imagine giving these to a computer or search engine today. The first one is ok, but following that, not so much.</p>
<ul>
<li>What are the latest Hubble Telescope pictures? </li>
<li>When were these taken? </li>
<li>How much longer will it stay up? </li>
<li>How will the next space telescope be different? </li>
<li>Compare the efforts of all G7 nations to build orbiting observation platforms. </li>
</ul>
<p>Each of those questions presupposed the previous one. The computer must keep track of this. That last one is a real doozy—it’s asking the computer to synthesize information from multiple sources into a coherent, original response. We can’t even dream of something this advanced right now, but I believe it’s coming.</p>
<p>On the other hand, let’s take a different direction, more personal:</p>
<ul>
<li>Which of my friends are having a birthday in the next month? </li>
<li>What book should I read next? </li>
<li>What do I need to get at the store? </li>
<li>Where are my children? </li>
</ul>
<p>Is this possible to do today? Yes, technologically speaking.</p>
<p>It’s not technology that will hold us back. It’s us.</p>
<p><strong>Security, Privacy</strong></p>
<p>Think of what it means to have a computer able to access full context to answer any query you throw at it. It has to know <em>everything</em> about you. To give you good food recommendations, it has to know where you’ve eaten and how you liked it. To be able to answer arbitrary questions in context, it needs to record your every conversation, parse it,&#160; cross-reference it, and store it for later access. </p>
<p>In our current culture, what this means is tying together all systems. There are intimations of this happening. Every time you hear of a company providing an API to access its data, that’s a little piece of this context being hooked up. It means that the Computer now has access to your Facebook and LinkedIn data, so that when you search for “tortoise” it can see you’re a developer and a high-proportion of software developers want to actually download “TortoiseSVN”, not see pictures of reptiles. In fact, it probably means there is no such thing as Facebook (or any other social network) anymore. There is just one network filled with data.</p>
<p>It becomes even more intertwined. If I really want the computer to have full context of me, it should monitor what I watch on TV, what my tastes in music are, where I go, where I work, my habits, who I call, what I talk about, etc., etc., etc. It never ends.</p>
<p>Now, here’s the million-dollar question: who would agree to such invasive procedures, even if the benefit was enormous?</p>
<p>In many ways, we are agreeing to it all the time. We allow places like Amazon, Netflix, and iTunes to track all our purchases in order to give us decent recommendations (in the hope we’ll purchase more). We give up our privacy a bit when we get the grocery loyalty cards, or even credit cards. This is all tracked and correlated. In the case of recommendation systems, there is a tangible benefit for us,but the loyalty cards are less certainly valuable to us, other than lower prices (which is not an inherent benefit of those cards, just a marketing tactic). Indeed, <a href="http://news.bbc.co.uk/1/hi/technology/3639679.stm">studies</a> have shown for just how little we humans give up our privacy.</p>
<p>There are a few levels of security we need to worry about. At a low level, how much do you trust Google, or Microsoft, or Apple, or Amazon with your information? Right now, a lot of us trust them with a fair amount, but nowhere near our entire life’s story. We have it neatly segmented. Part in Amazon, part in Facebook, part in Google, part in all the other companies we deal with. If mistakes are made, consequences not thought through, we have problems like all our <a href="http://www.mediapost.com/publications/?fa=Articles.showArticleHomePage&amp;art_aid=88591">friends seeing what we’re purchasing</a>. </p>
<p>At a high level, we need to consider all of this context ending up in the wrong hands. Not just scammers and other low-lifes, but government, foreign and domestic. The potential for abuse is massive—so much so that most of us wouldn’t voluntarily agree to any of the unifying ideas in this essay in our lifetimes. We just don’t trust anybody that much.</p>
<p>In essence, a Star Trek-like computer would require massive amounts of “spyware” on every system in the world, all tied together in a massive database. This is possible (maybe even desired?) in a closed system like a ship, where everything is easily monitored and hierarchies of security are well-understood. In the world at large, it’s just scary.</p>
<p><strong>Economy and Altruism</strong></p>
<p>I believe another obstacle to this is money. The way our society works, with limited resources, we are required (?) to have some system of trade, an economy. These days, the trade is often over information, the very thing this mythical Star Trek computer depends on. Think credit reports, buying history, demographics.</p>
<p>What is the specific danger of businesses finding out personal information about you? Can they force you to buy something? Not likely. But they can manipulate the environment in such a way to make it more likely. They present a lie designed to sell you something you don’t need. More maliciously, they can also sell your information to more vital entities, like insurance companies, or governments. If the government is too powerful, there is no way to prevent this. Think about what happens in China.</p>
<p>Is the only way to have such efficient and helpful systems to do away with our current capitalistic economy? Yes and no. Such far-reaching, life-changing technologies will undoubtedly continue to be developed and become more a part of our lives than they already are. Unfortunately, the potential for abuse is enormous and will grow as we become more and more dependent on them. We have no inherent trust in the system, nor should we. Just look at the ridiculous politicking taking place over voting machines. That’s just one system, and our society can’t get it right. We have a thousand such systems, many hanging onto usefulness and security by a thread. I bet that it’s not even the exception, but the rule to have such systems. Why should we trust such things to run our lives? We shouldn’t. There are so many reasons for this: corruption, economy, politics, and motivation.</p>
<p>Perhaps motivation is they key. We are often motivated now by money, comfort, or some other selfish reason—reasonable or not. In the Star Trek vision of the future, we see a population depicted as motivated by a quest for knowledge and understanding. That’s why they can have all-knowing computers. They trust who created it and what it does. They know there is no political or other ulterior motive. Yes, there’s adequate security and protections against attack, but the whole starting mindset is different.</p>
<p>Don’t think that I’m in favor of destroying capitalism in favor of more socialistic or idealistic systems. Imposing a system of “fairness” or “equality” does nothing to further those goals and I’m not advocating any political or economic system—I’m merely stating what I think the reality must be in the future for us to make these advancements. People themselves must reform their motivations. Pushing any political system has no effect because the fundamentals of our world haven’t changed. Resources are still scarce, thus economy must still exist. If people’s intrinsic motivations are to be changed, I believe resources must be (practically) infinite.</p>
<p>When this happens the nature of the Internet will change as well. If the economics change and we are no longer concerned with that, and we also have an altruistic frame of mind, information that is posted on the Internet will similarly change. No longer do we have to actually care about our walled gardens—the information is just put “up there”, in the “cloud”, to use the popular term. A computer would be free to just quote the contents to the user, or recombine it with other content. It’s all just content, with a single interface to access it all.</p>
<p><strong>Understanding</strong></p>
<p>There’s an important issue I glossed over in the above paragraphs. That is understanding. I talked a little about this in my previous blog entry about <a href="http://www.philosophicalgeek.com/2008/11/03/software-creativity-and-strange-loops/">Software Creativity and Strange Loops</a>.</p>
<p>I’m excited for this future. I doubt I’ll live to see advances fully along these lines. The problems are phenomenally difficult and they’re not all technical, but it’s still exciting to think about. Those of us who can just need to do our small part to contribute towards it.</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/ai/" title="AI" rel="tag">AI</a>, <a href="http://www.philosophicalgeek.com/tag/computer/" title="computer" rel="tag">computer</a>, <a href="http://www.philosophicalgeek.com/tag/privacy/" title="privacy" rel="tag">privacy</a>, <a href="http://www.philosophicalgeek.com/tag/security/" title="security" rel="tag">security</a>, <a href="http://www.philosophicalgeek.com/tag/star-trek/" title="star trek" rel="tag">star trek</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/11/17/consequences-of-a-star-trek-like-computer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Software Creativity and Strange Loops</title>
		<link>http://www.philosophicalgeek.com/2008/11/03/software-creativity-and-strange-loops/</link>
		<comments>http://www.philosophicalgeek.com/2008/11/03/software-creativity-and-strange-loops/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 02:11:15 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[A Better Future]]></category>

		<category><![CDATA[Books]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Thoughts On Tech and More]]></category>

		<category><![CDATA[creativity]]></category>

		<category><![CDATA[future]]></category>

		<category><![CDATA[intelligence]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[star trek]]></category>

		<category><![CDATA[strange loop]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/11/03/software-creativity-and-strange-loops/</guid>
		<description><![CDATA[I’ve been thinking a lot lately about the kind of technology and scientific understanding that would need to go into a computer like the one on the Enterprise in Star Trek, and specifically its interaction with people. It’s a computer that can respond to questions in context—that is, you don’t have to restart in every [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been thinking a lot lately about the kind of technology and scientific understanding that would need to go into a computer like the one on the Enterprise in Star Trek, and specifically its interaction with people. It’s a computer that can respond to questions in context—that is, you don’t have to restart in every question everything needed to answer. The computer has been monitoring the conversation and has thus built up a context that it can use to understand and intelligently respond.</p>
<p>A computer that records and correlates conversations real-time must have a phenomenal ability (compared to our current technology) to not just syntactically parse the content, but also construct semantic models of it. If a computer is going to respond intelligently to you, it has to understand you. This is far beyond our current technology, but we’re moving there. In 20 years who knows where this will be. In 100, we can’t even imagine it. 400 years is nearly beyond contemplation.</p>
<p>The philosophy of computer understanding, and human-computer interaction specifically is incredibly interesting. I was led to think a lot about this while reading Robert Glass’s <a href="http://www.amazon.com/gp/product/0977213315?ie=UTF8&amp;tag=philosophic0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0977213315">Software Creativity 2.0</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=philosophic0d-20&amp;l=as2&amp;o=1&amp;a=0977213315" width="1" border="0" />. This book is about the design and construction of software, but it has a deep philosophical undercurrent running throughout that kept me richly engaged. Much of the book is presented as conflicts between opposing forces:</p>
<ul>
<li>Discipline versus Flexibility </li>
<li>Formal Methods versus Heuristics </li>
<li>Optimizing versus <a href="http://en.wikipedia.org/wiki/Satisficing">satisficing</a> </li>
<li>Quantitative versus qualitative reasoning </li>
<li>Process versus product </li>
<li>Intellectual versus clerical </li>
<li>Theory versus practice </li>
<li>Industry versus academe </li>
<li>Fun versus getting serious </li>
</ul>
<p>Too often, neither one of these sides is “right”—they are just part of the problem (or the solution). While the book was written from the perspective of software construction, I think you can twist the intention just a little and consider them as attributes of software itself, not just how to write it, but how software must function. Most of those titles can be broken up into a dichotomy of Thinking versus Doing.</p>
<p><strong>Thinking</strong>: Flexibility, Heuristics, Satisficing, Qualitative, Process, Intellectual, Theory, Academe</p>
<p><strong>Doing</strong>: Discipline, Formal Methods, Optimizing, Quantitative, Product, Clerical, Practice, Industry</p>
<p>Computers are wonderful at the doing, not so much at the thinking. Much of thinking is synthesizing information, recognizing patterns, and highlighting the important points so that we can understand it. As humans, we have to do this or we are overwhelmed and have no comprehension. A computer has no such requirement—all information is available to it, yet it has no capability to synthesize, apply experience and perhaps (seemingly) unrelated principles to the situation. In this respect, the computer’s advantage in quantity is far outweighed by its lack of understanding. It has all the context in the world, but no way to apply it.</p>
<p>A good benchmark for a reasonable AI on the level I’m dreaming about is a program that can synthesize a complex set of documents (be they text, audio, or video) and produce a comprehensible summary that is not just selected excerpts from each. This functionality implies an ability to understand and comprehend on many levels. To do this will mean a much deeper understanding of the problems facing us in computer science, as represented in the list above.</p>
<p>You can start to think of these attributes/actions as mutually beneficial and dependent, influencing one another, recursively, being distinct (at&#160; first), and then morphing into a spiral, both being inputs to the other. Quantitative reasoning leads to qualitative analysis which leads back to qualitative measures, etc. </p>
<p>It made me think of Douglas R. Hofstadter’s opus <a href="http://www.amazon.com/gp/product/0465026567?ie=UTF8&amp;tag=philosophic0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0465026567">Godel, Escher, Bach: An Eternal Golden Braid</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=philosophic0d-20&amp;l=as2&amp;o=1&amp;a=0465026567" width="1" border="0" />. This is a fascinating book that, if you can get through it (I admit I struggled through parts), wants you to think of consciousness as the attempted resolution of a very high-order <em>strange loop</em>. </p>
<blockquote><p>The Strange Loop phenomenon occurs whenever, by moving upwards (or downwards) through the levels of some hierarchical system, we unexpectedly find ourselves right back where we started. </p>
</blockquote>
<p>In the book, he discusses how this pattern appears in many areas, most notably music, the works of <a href="http://search.live.com/images/results.aspx?q=escher&amp;FORM=BIRE#">Escher</a>, and in philosophy, as well as consciousness.</p>
<blockquote><p>My belief is that the explanations of “emergent” phenomena in our brains—for instance, ideas, hopes, images, analogies, and finally consciousness and free will—are based on a kind of Strange Loop, an interaction between levels in which the top level reaches back down towards the bottom level and influences it, while at the same time being itself determined by the bottom level. In other words, a self-reinforcing “resonance” between different levels… The self comes into being at the moment it has the power to reflect itself.</p>
</blockquote>
<p>I can’t help but think that this idea of a strange loop, combined with Glass’s attributes of software creativity are what will lead to more intelligent computers. </p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/creativity/" title="creativity" rel="tag">creativity</a>, <a href="http://www.philosophicalgeek.com/tag/future/" title="future" rel="tag">future</a>, <a href="http://www.philosophicalgeek.com/tag/intelligence/" title="intelligence" rel="tag">intelligence</a>, <a href="http://www.philosophicalgeek.com/tag/programming/" title="programming" rel="tag">programming</a>, <a href="http://www.philosophicalgeek.com/tag/star-trek/" title="star trek" rel="tag">star trek</a>, <a href="http://www.philosophicalgeek.com/tag/strange-loop/" title="strange loop" rel="tag">strange loop</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/11/03/software-creativity-and-strange-loops/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I&#8217;m a PC</title>
		<link>http://www.philosophicalgeek.com/2008/10/24/im-a-pc/</link>
		<comments>http://www.philosophicalgeek.com/2008/10/24/im-a-pc/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 00:14:21 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[apple]]></category>

		<category><![CDATA[tv]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/10/24/im-a-pc/</guid>
		<description><![CDATA[Judging, by the blogosphere’s reaction, I’m one of the few people who liked the Gates-Seinfeld ads by Microsoft. They were odd, sure, but it got people thinking, talking, going WTF? – and that can’t be bad.
But I definitely like the I’m a PC ads better. I was at the company meeting when they debuted, and [...]]]></description>
			<content:encoded><![CDATA[<p><img style="display: inline; margin: 0px 5px 0px 0px" src="http://blogs.msdn.com/blogfiles/stevecla01/WindowsLiveWriter/GetyourImaPCbadge_13387/display_picture_0006_10_2.gif" align="left" />Judging, by the blogosphere’s reaction, I’m one of the few people who liked the <a href="www.microsoft.com/windows/gates-and-seinfeld.aspx">Gates-Seinfeld ads</a> by Microsoft. They were odd, sure, but it got people thinking, talking, going WTF? – and that can’t be bad.</p>
<p>But I definitely like the <a href="http://imapc.lifewithoutwalls.com/">I’m a PC ads</a> better. I was at the company meeting when they debuted, and they immediately sparked a rumble in the audience—a positive one.</p>
<p>The cool thing is you can <a href="http://imapc.lifewithoutwalls.com/">upload your own picture or video</a> with your “I’m a PC” acting debut.</p>
<p>There are some interesting ones: a guy singing in the shower, for instance. Steve Ballmer’s is worth a look.</p>
<p>The greatest thing about these ads, though, is that they essentially take all the wind out of the obnoxious Apple ads that have been on for years.</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/apple/" title="apple" rel="tag">apple</a>, <a href="http://www.philosophicalgeek.com/tag/microsoft/" title="microsoft" rel="tag">microsoft</a>, <a href="http://www.philosophicalgeek.com/tag/tv/" title="tv" rel="tag">tv</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/10/24/im-a-pc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My universe rebalances</title>
		<link>http://www.philosophicalgeek.com/2008/10/20/my-universe-rebalances/</link>
		<comments>http://www.philosophicalgeek.com/2008/10/20/my-universe-rebalances/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 22:43:14 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/10/20/my-universe-rebalances/</guid>
		<description><![CDATA[Do you ever get the feeling that when things are going too well, something has to give?
I think sometimes the universe decides it needs to humble you, remind you just how thin the thread is from which we all hang. Months of comparative ease and happiness demand a balance.
Yesterday, we were rebalanced. Now, I realize [...]]]></description>
			<content:encoded><![CDATA[<p>Do you ever get the feeling that when things are going too well, something has to give?</p>
<p>I think sometimes the universe decides it needs to humble you, remind you just how thin the thread is from which we all hang. Months of comparative ease and happiness demand a balance.</p>
<p>Yesterday, we were rebalanced. Now, I realize that our misfortunes pale in comparison the suffering that many peoples of world undergo daily, never mind the financial turmoil we’re going through at the moment. </p>
<p>In fact, the individual events that happened to us aren’t really all that notable—it’s the juxtaposition that is suspicious.</p>
<p>We were out yesterday at an event and when we tried to leave, our car did not start. The gas was low (my wife was happy to remind me that she mentioned that we should have filled up the previous night), but I didn’t really think that was it. Still, one of our newly-made friends runs home to get gas, but the nozzle is made for a lawnmower, not a car, so it doesn’t reach. Someone else goes home to get a funnel. We put 3 gallons in there—just to be certain. It still doesn’t start. First impressions are wonderful, aren’t they? (at least they don’t think I’m an idiot for running out of gas). The car eventually gets towed to a local garage (turns out it’s a bad ignition coil). </p>
<p>When we get home, we set up a little of the furniture we’ve gotten for our house—we decide it doesn’t look nearly so good as we thought—this is demoralizing, to say the least.</p>
<p>Then I foolishly put something into the dishwasher that had been covered with soap (from the move). Next time I walked into the kitchen, the floor was covered with bubbles. Fun.</p>
<p>To end the day, I noticed that a screw was coming out of my glasses and I take it out to try to reseat it. Oops. 90 minutes later I got it back in.</p>
<p>&lt;sigh&gt;</p>
<p>Today was better, though.</p>
<p>I’ve got some blog topics planned—it’s just been too hectic to have time to write lately. I didn’t even have a computer desk until yesterday, and it still doesn’t have a computer under it. Maybe today…</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/personal/" title="Personal" rel="tag">Personal</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/10/20/my-universe-rebalances/feed/</wfw:commentRss>
		</item>
		<item>
		<title>On the importance of having a good haircut</title>
		<link>http://www.philosophicalgeek.com/2008/10/11/on-the-importance-of-having-a-good-haircut/</link>
		<comments>http://www.philosophicalgeek.com/2008/10/11/on-the-importance-of-having-a-good-haircut/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 03:41:36 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Humor]]></category>

		<category><![CDATA[Personal]]></category>

		<category><![CDATA[haircut]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[pictures]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/10/11/on-the-importance-of-having-a-good-haircut/</guid>
		<description><![CDATA[Note to future self: Don&#8217;t get haircut the week before important events take place. 
After my last day of work at GeoEye, I went to get my haircut at a nearby salon. I asked for it a little shorter. Between the time I gave this brief instruction, and the time she lifted her hands to [...]]]></description>
			<content:encoded><![CDATA[<p>Note to future self: Don&#8217;t get haircut the week before important events take place. </p>
<p>After my last day of work at GeoEye, I went to get my haircut at a nearby salon. I asked for it a little shorter. Between the time I gave this brief instruction, and the time she lifted her hands to my head, a seismic, cosmic, interrupting event took place that transformed my words into: &#8220;Kindly shave my head, I have no need of hair. Please don&#8217;t ask for confirmation.&#8221;</p>
<p>At least, that&#8217;s what I assume happened. Before I could say anything, an electric razor had taken quite a bit off the top. It wasn&#8217;t to the skin&#8211;thank goodness. But I was on my way to a whole new look.</p>
<p>It was too late to fix it, so I went with it. </p>
<p>The next day we flew out to Seattle to look for housing with our new realtor. I had to excuse myself for looking like a skinhead.</p>
<p>Of course, the next Monday I started at Microsoft and had my badge picture taken. That one will be alive for a while&#8230;</p>
<p>And my drivers license&#8230;</p>
<p>And all the pictures of my wife and I in a new location&#8230;</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/haircut/" title="haircut" rel="tag">haircut</a>, <a href="http://www.philosophicalgeek.com/tag/humor/" title="Humor" rel="tag">Humor</a>, <a href="http://www.philosophicalgeek.com/tag/microsoft/" title="microsoft" rel="tag">microsoft</a>, <a href="http://www.philosophicalgeek.com/tag/pictures/" title="pictures" rel="tag">pictures</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/10/11/on-the-importance-of-having-a-good-haircut/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Goodbye Google Ads</title>
		<link>http://www.philosophicalgeek.com/2008/09/28/goodbye-google-ads/</link>
		<comments>http://www.philosophicalgeek.com/2008/09/28/goodbye-google-ads/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 23:14:37 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[advertising]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/09/28/goodbye-google-ads/</guid>
		<description><![CDATA[Given that I&#8217;m now working for its major competitor, I&#8217;ve decided to take down the Google ads from this site. I hope this leads to less clutter and intrusiveness. My goal for this site has been (and still is) for it to be self-sustaining, and I hope it can continue to be through Amazon referrals.

	Tags: [...]]]></description>
			<content:encoded><![CDATA[<p>Given that I&#8217;m now working for its major competitor, I&#8217;ve decided to take down the Google ads from this site. I hope this leads to less clutter and intrusiveness. My goal for this site has been (and still is) for it to be self-sustaining, and I hope it can continue to be through Amazon referrals.</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/advertising/" title="advertising" rel="tag">advertising</a>, <a href="http://www.philosophicalgeek.com/tag/google/" title="google" rel="tag">google</a>, <a href="http://www.philosophicalgeek.com/tag/microsoft/" title="microsoft" rel="tag">microsoft</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/09/28/goodbye-google-ads/feed/</wfw:commentRss>
		</item>
		<item>
		<title>First two weeks at Microsoft</title>
		<link>http://www.philosophicalgeek.com/2008/09/28/first-two-weeks-at-microsoft/</link>
		<comments>http://www.philosophicalgeek.com/2008/09/28/first-two-weeks-at-microsoft/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 23:09:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[jobs]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/09/28/first-two-weeks-at-microsoft/</guid>
		<description><![CDATA[It has been an insane first couple of weeks at Microsoft. In actuality, though, I don&#8217;t know if I can count it as two weeks of experience. I&#8217;ve had two days of orientation, one day for the company meeting (which was awesome, by the way), and two more days for training in Live Search specifically. [...]]]></description>
			<content:encoded><![CDATA[<p>It has been an insane first couple of weeks at Microsoft. In actuality, though, I don&#8217;t know if I can count it as two weeks of experience. I&#8217;ve had two days of orientation, one day for the company meeting (which was awesome, by the way), and two more days for training in Live Search specifically. So really I&#8217;ve had only a week of work.</p>
<p>The team I&#8217;m working in is great. Everybody really knows their stuff and it&#8217;s fairly intimidating trying to comprehend all the knowledge (both project and organizational) that you need to drink from the fire hose. Supposedly, it takes an average of 6 months before most people feel like they&#8217;re contributing 100%. That seems like a really, really long time, given how fast things move in the Internet age. So far, I&#8217;ve mostly read code (fixed one small bug, and found another), and done online training (of which there is a LOT&#8211;you don&#8217;t have to do everything, but there&#8217;s a an awful lot there to choose from). It&#8217;s easy to start feeling caught between wanting to contribute as soon as possible and not wanting to screw up other people&#8217;s work.</p>
<p>I&#8217;ve also got to come up with my yearly commitments this week&#8211;a daunting task when you don&#8217;t know anything. <img src='http://www.philosophicalgeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Thankfully, my lead is a lot of help. There&#8217;s a nice big section for personal development and I&#8217;m planning on reading Scott Meyer&#8217;s <a href="http://www.amazon.com/gp/product/0321334876?ie=UTF8&amp;tag=philosophic0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321334876">Effective C++</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=philosophic0d-20&amp;l=as2&amp;o=1&amp;a=0321334876" width="1" border="0"/> and <a href="http://www.amazon.com/gp/product/020163371X?ie=UTF8&amp;tag=philosophic0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=020163371X">More Effective C++</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=philosophic0d-20&amp;l=as2&amp;o=1&amp;a=020163371X" width="1" border="0"/>. They&#8217;ve been on my list for a while, but now I can get graded on it!</p>
<p>I don&#8217;t know if I&#8217;ve mentioned it explicitly before, but I&#8217;m working on the Webmaster team as part of <a href="http://www.live.com/">Live Search</a>. The <a href="http://webmaster.live.com/">Webmaster tools</a> are the interface between web site owners and the Live search index. If you have a web site, you should definitely create an account with our tools so you can see how your site is performing.</p>
<p><strong>About Live Search in general&#8230;</strong></p>
<p>Over a year ago I briefly tried Live Search as my main search engine, but quickly moved back to Google. About 6 months ago (before I was contacted about the job at Microsoft, incidentally), I decided to look at Live again&#8211;HUGE improvement. I have very rarely gone back to Google since then.</p>
<p>There are also some really exciting new features coming for both Live and the webmaster tools, so give them a try now and again in a few months. I can also personally attest to the fact that the Live Search team takes feedback seriously. If you have any issue with your site, or the results of your query&#8211;write up a little note and send it to the <a href="https://feedback.live.com/default.aspx?productkey=wlsearch">feedback page</a>, or even send me an e-mail and I can make sure it gets sent to the right people. </p>
<p><strong>P.S.</strong> My <a href="http://www.philosophicalgeek.com/2008/08/10/my-interview-experience-at-microsoft/">blog entry about my interview experience</a> did make the rounds and a number of people commented to me on it&#8230;.weird feeling&#8230;more <em>infamous</em>, than famous. Lesson: Make sure you never writing something you wouldn&#8217;t mind other people reading back to you. (I don&#8217;t think I did&#8230;)</p>

	Tags: <a href="http://www.philosophicalgeek.com/tag/jobs/" title="jobs" rel="tag">jobs</a>, <a href="http://www.philosophicalgeek.com/tag/microsoft/" title="microsoft" rel="tag">microsoft</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/09/28/first-two-weeks-at-microsoft/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting OLE_COLOR to System.Drawing.Color</title>
		<link>http://www.philosophicalgeek.com/2008/09/13/converting-ole_color-to-systemdrawingcolor/</link>
		<comments>http://www.philosophicalgeek.com/2008/09/13/converting-ole_color-to-systemdrawingcolor/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 03:45:42 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[.net]]></category>

		<category><![CDATA[color]]></category>

		<guid isPermaLink="false">http://www.philosophicalgeek.com/2008/09/13/converting-ole_color-to-systemdrawingcolor/</guid>
		<description><![CDATA[
I&#8217;ve been working on a project using Visual Studio Tools for Office 2008 (VSTO) and at one point I needed to get the colors for categories in Outlook 2007. There are actually 3 colors, and they are returned as uint&#8217;s&#8211;why the .Net wrappers don&#8217;t convert to colors for you, I don&#8217;t know (to avoid linking [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense--></p>
<p>I&#8217;ve been working on a project using <a href="http://msdn.microsoft.com/en-us/office/aa905533.aspx">Visual Studio Tools for Office 2008 (VSTO)</a> and at one point I needed to get the colors for categories in Outlook 2007. There are actually 3 colors, and they are returned as uint&#8217;s&#8211;why the .Net wrappers don&#8217;t convert to colors for you, I don&#8217;t know (to avoid linking to System.Drawing?). </p>
<p>The important thing is to convert them into the friendly System.Drawing.Color objects I know and love. For this task, there exists a handy <a href="http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator_members.aspx">ColorTranslator</a> class. There is a FromOle method that does the exact chore you need. Here&#8217;s a sample of my code:</p>
<p>&nbsp;</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> GetCategoryColors()</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">foreach</span> (OutlookLib.Category category <span style="color: #0000ff">in</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>         Application.ActiveExplorer().Session.Categories)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         CategoryColor color = <span style="color: #0000ff">new</span> CategoryColor(</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>             ColorTranslator.FromOle((Int32)category.CategoryGradientTopColor),</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>             ColorTranslator.FromOle((Int32)category.CategoryGradientBottomColor),</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>             ColorTranslator.FromOle((Int32)category.CategoryBorderColor));</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>         _categoryCollection[category.Name] = color;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span> }</pre>
</div>
</div>

	Tags: <a href="http://www.philosophicalgeek.com/tag/net/" title=".net" rel="tag">.net</a>, <a href="http://www.philosophicalgeek.com/tag/color/" title="color" rel="tag">color</a>, <a href="http://www.philosophicalgeek.com/tag/tips/" title="Tips" rel="tag">Tips</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.philosophicalgeek.com/2008/09/13/converting-ole_color-to-systemdrawingcolor/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
