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

<channel>
	<title>IBlog &#187; Programming</title>
	<atom:link href="http://blog.objectpattern.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.objectpattern.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 31 Oct 2011 15:03:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WaitHandles&#8217; Switch</title>
		<link>http://blog.objectpattern.com/dot-net/waithandles-switch/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=waithandles-switch</link>
		<comments>http://blog.objectpattern.com/dot-net/waithandles-switch/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 10:27:13 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.objectpattern.com/dot-net/waithandles-switch/</guid>
		<description><![CDATA[I will say it again: “I like extension methods”. They provide great way of increase readability of the code in languages like C#.
Anyway this post is not about extension method. Have you ever needed to write code that will wait on different wait handles (WaitHandle) and execute different piece of code depending up on which [...]]]></description>
			<content:encoded><![CDATA[<p>I will say it again: “I like extension methods”. They provide great way of increase readability of the code in languages like C#.</p>
<p>Anyway this post is not about extension method. Have you ever needed to write code that will wait on different wait handles (<a href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.aspx">WaitHandle</a>) and execute different piece of code depending up on which handle is signaled. Here is one way to implement that:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> WaitSwitch(<span class="kwrd">this</span> WaitHandle[] waitHandles, <span class="kwrd">params</span> Action[] actions)</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>    waitHandles.DoEmptyOrNullArgCheck(<span class="str">&quot;waitHandles&quot;</span>);</pre>
<pre><span class="lnum">   4:  </span>    actions.DoEmptyOrNullArgCheck(<span class="str">&quot;waitHandles&quot;</span>);</pre>
<pre class="alt"><span class="lnum">   5:  </span>&#160;</pre>
<pre><span class="lnum">   6:  </span>    <span class="kwrd">if</span> (waitHandles.Length != actions.Length)</pre>
<pre class="alt"><span class="lnum">   7:  </span>        <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentException(<span class="str">&quot;length of wait handles and actions has to be same&quot;</span>);</pre>
<pre><span class="lnum">   8:  </span>&#160;</pre>
<pre class="alt"><span class="lnum">   9:  </span>    var triggerIndex = WaitHandle.WaitAny(waitHandles);</pre>
<pre><span class="lnum">  10:  </span>    actions[triggerIndex]();</pre>
<pre class="alt"><span class="lnum">  11:  </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>And then client code will become as:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>(<span class="kwrd">new</span>[] { shutdownTriggeredEvent, updateAvailableEvent }).WaitSwitch(</pre>
<pre><span class="lnum">   2:  </span>    () =&gt; isShutdownRequested = <span class="kwrd">true</span>, </pre>
<pre class="alt"><span class="lnum">   3:  </span>    DownloadNextUpdate</pre>
<pre><span class="lnum">   4:  </span>);</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/waithandles-switch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending code readability by extension methods</title>
		<link>http://blog.objectpattern.com/dot-net/extending-code-readability-by-extension-methods/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=extending-code-readability-by-extension-methods</link>
		<comments>http://blog.objectpattern.com/dot-net/extending-code-readability-by-extension-methods/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 05:40:56 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.objectpattern.com/?p=50</guid>
		<description><![CDATA[If you haven’t noticed, note that extension methods can also be called on null objects. Meaning, there can be extension method which checks whether an object is null or not. So, 
public void Operate(InputType inputObject)
{
    if (null != inputObject)
    {
        . . [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven’t noticed, note that extension methods can also be called on null objects. Meaning, there can be extension method which checks whether an object is null or not. So, </p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (<span class="kwrd">null</span> != inputObject)
    {
        . . .
    }
} 

<span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (<span class="kwrd">null</span> == inputObject)
    {
        . . .
    }
} </pre>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Can be replaced by</p>
<pre class="csharpcode"><span class="kwrd"></span>&nbsp;</pre>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (inputObject.IsNotNull())
    {
        . . .
    }
} 

<span class="kwrd">public</span> <span class="kwrd">void</span> Operate(InputType inputObject)
{
    <span class="kwrd">if</span> (inputObject.IsNull())
    {
        . . .
    }
} </pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/extending-code-readability-by-extension-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending email message having embedded image (.NET)</title>
		<link>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-email-message-having-embedded-image-net</link>
		<comments>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/#comments</comments>
		<pubDate>Fri, 15 May 2009 05:16:25 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">/post/Sending-email-message-having-embedded-image-(NET).aspx</guid>
		<description><![CDATA[Does your .net application send email messages? Does it send formatted email messages? I think applications should always send formatted email messages instead of text only. (Are asking why? Simple, formatted messages are much more capable, presentable, &#8230;).
Counter argument: Some user uses email client that are not capable to show HTML messages. Or someone is [...]]]></description>
			<content:encoded><![CDATA[<p>Does your .net application send email messages? Does it send formatted email messages? I think applications should always send formatted email messages instead of text only. (Are asking why? Simple, formatted messages are much more capable, presentable, &#8230;).</p>
<p>Counter argument: Some user uses email client that are not capable to show HTML messages. Or someone is doing it for security purpose. Okay, I agree, then send both the views; text view as well as HTML view. Using .NET, one can send multi view email messages, depending on email client settings and/or capability, client is expected to pick the right view and shows that to the user.</p>
<p>Next question is, say we have decided to send email in html and text view, can we send images and style sheets embedded with email? Answers is yes. Here is how one can send multi-part email message using .net libraries that has embedded image.</p>
<p>Here goes the first step, create MailMessage object and setup that with appropriate values</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.3%; font-family: consolas, 'Courier New', courier, monospace; height: 60px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> var from = <span style="color: #0000ff">new</span> MailAddress(<span style="color: #006080">"admin@objectpattern.com"</span>, <span style="color: #006080">"Himanshu"</span>);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> var to = <span style="color: #0000ff">new</span> MailAddress(<span style="color: #006080">"himanshu@objectpattern.net"</span>);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> var message = <span style="color: #0000ff">new</span> MailMessage(from, to) { Subject = <span style="color: #006080">"Hi from ObjectPattern"</span>};</pre>
</div>
</div>
<p>next step changes. As we want to have two views &#8211; text and html, we will have to create email body differently.</p>
<p>in these lines of code, there are certain important points</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.59%; font-family: consolas, 'Courier New', courier, monospace; height: 281px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> <span style="color: #008000">//creating text view</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> var textViewContent = <span style="color: #006080">"Test content for text view"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> var textView = AlternateView.CreateAlternateViewFromString(textViewContent, Encoding.UTF8,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span>                                                            MediaTypeNames.Text.Plain);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   5:</span> <span style="color: #008000">//creating html view </span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   6:</span> var htmlViewContent = <span style="color: #006080">"

Html content containing image logo

Thanks,
ObjectPattern
<img src="cid:logo.png" alt="logo" />"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   7:</span> var htmlView = AlternateView.CreateAlternateViewFromString(htmlViewContent, Encoding.UTF8,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   8:</span>                                                            MediaTypeNames.Text.Html);</pre>
</div>
</div>
<p>that I would like to bring in to your notice.</p>
<ul>
<li>Notice that we are not assigning Body property of MailMessage type</li>
<li>While creating view, we are specifying media type name as either plain text or html text, it can also be rich text.</li>
<li>We have created an img tag that referring to source as &#8216;cid:logo.png&#8217;</li>
</ul>
<p>okay now how we will embed image into email message? That&#8217;s easy as well:</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.66%; font-family: consolas, 'Courier New', courier, monospace; height: 76px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> var logo = <span style="color: #0000ff">new</span> LinkedResource(<span style="color: #006080">"images/logo.png"</span>, MediaTypeNames.Image.Jpeg) {ContentId = <span style="color: #006080">"logo.png"</span>};</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> htmlView.LinkedResources.Add(logo);</pre>
</div>
</div>
<p>here in first line, first parameter of constructor (&#8220;image/logo.png&#8221; text) specifies the path of the image file. One can also supply image content as stream if its not coming directly from the file. Now remember, in above section, we had specified the src attribute of img tag, that should match with content id. Else image will not be shown correctly in email client. Also notice that we are adding this image to html view.</p>
<p>We are almost done now. All we need to do now is to add views to message object and sending using SMTP client.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 99.11%; font-family: consolas, 'Courier New', courier, monospace; height: 58px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> message.AlternateViews.Add(textView);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> message.AlternateViews.Add(htmlView);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Knowing memory usage from Compact Framework application</title>
		<link>http://blog.objectpattern.com/compact-framework/knowing-memory-usage-from-compact-framework-application/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=knowing-memory-usage-from-compact-framework-application</link>
		<comments>http://blog.objectpattern.com/compact-framework/knowing-memory-usage-from-compact-framework-application/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 18:50:38 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows Plateform]]></category>

		<guid isPermaLink="false">/post/Knowing-memory-usage-from-Compact-Framework-application.aspx</guid>
		<description><![CDATA[For any handheld device application, memory usage is an important element to observer. .NET Compact framework have very less code that gives information about physical or virtual memory. But using native libraries &#8211; by doing pInvoke, one can retrieve memory usage statistics.
There can be more than one level of report that can be captured. Today, [...]]]></description>
			<content:encoded><![CDATA[<p>For any handheld device application, memory usage is an important element to observer. .NET Compact framework have very less code that gives information about physical or virtual memory. But using native libraries &#8211; by doing pInvoke, one can retrieve memory usage statistics.</p>
<p>There can be more than one level of report that can be captured. Today, lets start with summary. GlobalMemoryStatus function in coredll can help identifying how much total physical memory available in the device and how much of it is free. Same way, how much of virtual memory available to process and how much of it is free.</p>
<p>Lets see how can we use GlobalMemoryStatus. We will have to define a class which will be passed to function and will be filled by GlobalMemoryStatus function. Layout of it is defined as structure by MS team, but its alright to use class here. By having it as class, we will be able to write default constructor unlike structure in C#.</p>
<pre class="csharpcode">    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    <span class="kwrd">internal</span> <span class="kwrd">class</span> MemoryStatus
    {
        <span class="kwrd">public</span> <span class="kwrd">uint</span> dwLength;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> dwMemoryLoad;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullTotalPhys;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullAvailPhys;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullTotalPageFile;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullAvailPageFile;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullTotalVirtual;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullAvailVirtual;
        <span class="kwrd">public</span> <span class="kwrd">uint</span> ullAvailExtendedVirtual;
        <span class="kwrd">public</span> MemoryStatus()
        {
            <span class="kwrd">this</span>.dwLength = (<span class="kwrd">uint</span>)Marshal.SizeOf(<span class="kwrd">typeof</span>(MemoryStatus));
        }
    }
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now, lets define extern method for GlobalMemoryStatus</p>
<pre class="csharpcode">        [<span class="kwrd">return</span>: MarshalAs(UnmanagedType.Bool)]
        [DllImport(<span class="str">"coredll.dll"</span>, CharSet = CharSet.Auto, SetLastError = <span class="kwrd">true</span>, EntryPoint = <span class="str">"GlobalMemoryStatus"</span>)]
        <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">bool</span> GlobalMemoryStatusWinCE([In, Out] MemoryStatus lpBuffer);
</pre>
<p>And here is how we can call the method</p>
<pre class="csharpcode">    MemoryStatus internalReport = <span class="kwrd">new</span> MemoryStatus();
    <span class="kwrd">if</span> (GlobalMemoryStatusWinCE(internalReport))</pre>
<pre class="csharpcode">
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/compact-framework/knowing-memory-usage-from-compact-framework-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Navigate and injecting C# code using visual studio macro</title>
		<link>http://blog.objectpattern.com/dot-net/navigate-and-injecting-c-code-using-visual-studio-macro/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=navigate-and-injecting-c-code-using-visual-studio-macro</link>
		<comments>http://blog.objectpattern.com/dot-net/navigate-and-injecting-c-code-using-visual-studio-macro/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 19:32:00 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[VS.NET]]></category>

		<guid isPermaLink="false">/post/Navigate-and-injecting-C-code-using-visual-studio-macro.aspx</guid>
		<description><![CDATA[Visual studio macros are great, probably I will write this in all posts that I write for macros  . Sometime back, I need to change a fairly big CF.NET application such a way that it will log a line on each function entry and on function exit. We were tracing for cause of intermittently [...]]]></description>
			<content:encoded><![CDATA[<p>Visual studio macros are great, probably I will write this in all posts that I write for macros <img src='http://blog.objectpattern.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Sometime back, I need to change a fairly big CF.NET application such a way that it will log a line on each function entry and on function exit. We were tracing for cause of intermittently occurring GWES.EXE error, and we were tracing it from multiple directions. The error code of GWES was 0xC0000005, which means someone was trying to access something, which was never allocated or is being accessed after releasing it. Application was multi-threaded, and hence it was difficult to understand which thread will do what at what time.</p>
<p>Moving back to original point, we wanted to log entry and exit of each functions. There can be more then one way to do that, but we have selected to change each functions. And to change each functions I have selected to use developer named <em>&#8220;VS.NET macro&#8221;.</em></p>
<p>From macro it is possible to navigate through solution and projects. So macro first needs to find out all class types from a project, and then for each class, iterate through its member and find out functions that has body. If function has body, inject the code that logs line on function entry and exit.</p>
<p>It was easy to find function entry, but there can be many way function ends, like exception is being thrown, or based of some condition it may execute &#8220;return&#8221;, or body of the function is ended and hence return. To accommodate such cases, we decide to use &#8220;<em>using statement&#8221; </em>of C#.</p>
<p>All right, enough of the background, have look at Macro code <a title="VS.NET Macro" href="http://download.objectpattern.com/LoggingInjection-VS8Macro.vb" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/navigate-and-injecting-c-code-using-visual-studio-macro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending keystrokes (Key press) from .Net to active application</title>
		<link>http://blog.objectpattern.com/dot-net/sending-keystrokes-key-press-from-net-to-active-application/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-keystrokes-key-press-from-net-to-active-application</link>
		<comments>http://blog.objectpattern.com/dot-net/sending-keystrokes-key-press-from-net-to-active-application/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 17:32:39 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>

		<guid isPermaLink="false">/post/Sending-keystrokes-(Key-press)-from-Net-to-active-application.aspx</guid>
		<description><![CDATA[Many of the part of windows works on messages &#8211; windows messages. One code can send different kind of messages to another application using Windows API. Keyboard messages and mouse messages are one of them.
.NET is one more layer above OS, e.g. Windows. If someone needs to emulate keyboard strokes to another application from .NET [...]]]></description>
			<content:encoded><![CDATA[<p>Many of the part of windows works on messages &#8211; windows messages. One code can send different kind of messages to another application using Windows API. Keyboard messages and mouse messages are one of them.</p>
<p>.NET is one more layer above OS, e.g. Windows. If someone needs to emulate keyboard strokes to another application from .NET there is a choice of using .NET class library. To emulate keyboard events from .NET it&#8217;s easier to use</p>
<ul>
<li>System.Windows.Forms.SendKeys.Send(string) and </li>
<li>System.Windows.Forms.SendKeys.SendWait(string) </li>
</ul>
<p>Recently, I used this to auto log into a application that I&#8217;m developing if it&#8217;s debug build. Just to get a change from AutoHotKey. </p>
<p>The problem of this is it sends keystrokes to only active application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/sending-keystrokes-key-press-from-net-to-active-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VS.NET, macro creating string const, and macro creating string resource entry</title>
		<link>http://blog.objectpattern.com/dot-net/vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry</link>
		<comments>http://blog.objectpattern.com/dot-net/vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 14:08:00 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>
		<category><![CDATA[VS.NET]]></category>

		<guid isPermaLink="false">/post/VSNET-Macro-creating-const-of-string-and-resource-entry-for-string.aspx</guid>
		<description><![CDATA[
Per me, macro is one of the most important feature for any text editor or software IDE. And hence, it is very import for VS.NET user to understand and then use macros available in VS.NET. VS.NET macros are very powerfully tool and they help in lot more different ways.


I have created two macros that are [...]]]></description>
			<content:encoded><![CDATA[<p>
Per me, macro is one of the most important feature for any text editor or software IDE. And hence, it is very import for VS.NET user to understand and then use macros available in VS.NET. VS.NET macros are very powerfully tool and they help in lot more different ways.
</p>
<p>
I have created two macros that are very common in their need. While programming, we need to create string const on regular bases. It becomes inconvenient to go to top of the class while writing a method body for same class and create constant. Macro in library attached with this post becomes handy at that time.
</p>
<p>
Same use case hold very much true for creating string resources while writing method body. And it becomes really very easy if string resource can be created while writing method body.
</p>
<p>
For those who thinks like me (or want to <img src='http://blog.objectpattern.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ), I have attached two macros with this post. Macro works for VS.NET 2005, haven&#39;t tested in any other version. But should work fine in VS.NET 2003 or VS.NET 2008</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/vs-net-macro-creating-string-const-and-macro-creating-string-resource-entry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automation, Software Engineering, Productivity</title>
		<link>http://blog.objectpattern.com/programming/automation-software-engineering-productivity/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=automation-software-engineering-productivity</link>
		<comments>http://blog.objectpattern.com/programming/automation-software-engineering-productivity/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 12:22:00 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[RoboCoding]]></category>
		<category><![CDATA[VS.NET]]></category>

		<guid isPermaLink="false">/post/Automation2c-Software-Engineering2c-Productivity.aspx</guid>
		<description><![CDATA[It&#8217;s good to use computer as far as it is possible to do. Around the world, many computer engineers work for others to generate code-base that instructs computers to act as it&#39;s user would like it to. Computers gives more accessibility to the information, knowledge, gives more processing power, help to be more managed and [...]]]></description>
			<content:encoded><![CDATA[<p>It&rsquo;s good to use computer as far as it is possible to do. Around the world, many computer engineers work for others to generate code-base that instructs computers to act as it&#39;s user would like it to. Computers gives more accessibility to the information, knowledge, gives more processing power, help to be more managed and allow us to utilize much more clock cycle of our main thread &ndash; a human main thread, which can really do the thinking. Ultimately that what the difference is between human and machines in today edge. That is why we have many software built today. Operating systems, financial applications, engineering application and many others, including the RAD (Rapid application development) tools. RAD in compare to the edge where programmers need to punch the cards makes developer very efficient in generating computer instructions. And of-course even computers are also much more efficient now a days. </p>
<p>
Anyway, many of us knows most of above that I have written. The point here is use computers, as much as you can to increase productivity. And it applies to software engineers as well. To support that, I&rsquo;m planning to take several efforts that will include blog-posts, posting some tools, VS.NET macros, snippets and something else that will help.
</p>
<p>
Although this wouldn&rsquo;t be the only goal of this blog-post repository (making it explicit as this is first blog-post in this repository), I&rsquo;m starting with posting first version of first macro that creates resource entry of a selected <strong>string</strong> in the code. The macro is posted separately to make both more manageable. I&rsquo;m linking my first macro with this blog post <a href="http://blog.objectpattern.com/blogengine/post/VSNET-Macro-creating-const-of-string-and-resource-entry-for-string.aspx">here</a><strong>,</strong> but will not do same for other automation posts that I will post later. To find them you should see posts tagged under <em><a href="http://blog.objectpattern.com/blog/category/RoboCoding.aspx">RoboCoding</a></em>. Please mind that the macro is in version-1, I will fix and enhance it as time ticks and the need. As well as more of such will come in future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/programming/automation-software-engineering-productivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

