<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://community.opennetcf.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Compact Framework</title><subtitle type="html" /><id>http://community.opennetcf.com/articles/cf/atom.aspx</id><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/default.aspx" /><link rel="self" type="application/atom+xml" href="http://community.opennetcf.com/articles/cf/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20611.960">Community Server</generator><updated>2007-08-10T19:13:00Z</updated><entry><title>Determining Form and Process Changes in Windows CE</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2008/08/13/determining-form-and-process-changes-in-windows-ce.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2008/08/13/determining-form-and-process-changes-in-windows-ce.aspx</id><published>2008-08-13T21:41:00Z</published><updated>2008-08-13T21:41:00Z</updated><content type="html">





&lt;div class="Section1"&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;August 2008&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Christopher Tacke&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;OpenNETCF Consulting, LLC&lt;/p&gt;&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;



&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" alt="" align="middle" border="0" /&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200808/WindowWatcher/WindowWatcher.zip"&gt;Download the Source&lt;/a&gt;&lt;span class=""&gt;&lt;/span&gt;&lt;br /&gt;
&lt;font color="#0066cc"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" alt="" align="middle" border="0" height="30" /&gt;&amp;nbsp;&lt;/font&gt;
&lt;a href="http://community.opennetcf.com/blogs/cf/200805/GDI_Performance.pdf" class="" title="Download the PDF" target="_blank"&gt;
&lt;/a&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200808/WindowWatcher/Determining_Form_and_Process_Changes_in_Windows_CE.pdf"&gt;&lt;font color="#0066cc"&gt;Download the PDF&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;


&lt;h1&gt;Introduction&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;Windows CE, and especially Windows Mobile devices have a UI
paradigm that’s quite a bit different than the desktop.  As a general rule, only
one application, and indeed only one Form is typically ever in front of all
other applications because there usually isn’t enough real estate to show
multiple forms and MDI layout isn’t supported in CE.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;One of the things that this paradigm pushes us toward is
knowing either when the visible Form changes or when the user changes
applications completely.  We can use this for tracking state or even
implementing an application authentication scheme.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Unfortunately the Windows CE operating system simply doesn’t
provide us any kind of event to tell us when a Form has changed or when the
process has changed.  Sure, within our application we can watch things like the
Deactivate event on a Form, but when our Form gets deactivated, how do we
determine what’s on top now?  Is it another Form in our application, or another
application altogether?&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In this article we’ll take a look at a simple utility class
called WindowWatcher than can provide us feedback for these state changes
through a very simple managed event interface. &lt;/p&gt;

&lt;h1&gt;Window Handles and Process IDs&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;The key to our solution is the fact that all Forms are
Window and all Windows have a unique identifier called a Handle, or hWnd, and
that all processed have a unique identifier called a process identifier, or
PID.  There are Win32 APIs to retrieve these identifiers, and while there are
no corresponding managed-code methods that call them, a little P/Invoke gets us
there easily.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The Win32 APIs we’re going to be interested in are:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;table class="MsoTableGrid" style="border:medium none;margin-left:36.9pt;border-collapse:collapse;" cellpadding="0" cellspacing="0"&gt;
 
&lt;tr&gt;
  
&lt;td style="border:1pt solid black;padding:0in 5.4pt;width:202.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Win32 Method&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:solid solid solid none;border-color:black black black -moz-use-text-color;border-width:1pt 1pt 1pt medium;padding:0in 5.4pt;width:193.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Function&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:202.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;GetForegroundWindow&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:193.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Gets the handle, or hWnd, of the current topmost, visible Window&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:202.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;GetProcessID&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:193.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Gets the process identifier, or PID, of the calling process&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:202.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;GetWindowThreadProcessId&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:193.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Gets the PID that owns a specific hWnd&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;With just these three APIs we can determine when the
foreground Window has changed because the return value from GetForegroundWindow
will change, and we can determine if the new foreground Window is in a new
process because the PID retrieved from GetWindowThreadProcessId will change.&lt;/p&gt;

&lt;h1&gt;A Simple Solution&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;So armed with these APIs, and a general idea of how we can
determine the state changes we want, we can create a simple class that
encapsulates our logic.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;First we need to define a couple delegates for our events:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;delegate&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; &lt;span&gt;WindowChangedHandler&lt;/span&gt;(&lt;span style="color:blue;"&gt;bool&lt;/span&gt; processChanged, &lt;span style="color:blue;"&gt;bool&lt;/span&gt;
inMyProcess);&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;An event of this type will be raised any time the foreground
Window changes, and if the owner of the new Window is a new process, processChanged
will be true. In either case inMyProcess will tell us if the new foreground
Window is in the process that created our WindowWatcher class.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Now we implement the logic.  The core of the logic will be a
background thread that periodically checks the current foreground window.  To
be nice, we’ll make the interval adjustable.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt; Interval {
&lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Next we define some variables that we’ll maintain at class
scope to keep track of state between checks and initialize them in the class
constructor plus define the event of our delegate type:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt;
m_enabled;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt;
m_stopThread;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span&gt;IntPtr&lt;/span&gt;
m_lastForeWindow;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;uint&lt;/span&gt;
m_lastPID;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;uint&lt;/span&gt; m_myPID;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;event&lt;/span&gt; &lt;span&gt;WindowChangedHandler&lt;/span&gt; WindowChanged;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; WindowWatcher()&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;{&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_enabled = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_lastForeWindow = &lt;span&gt;IntPtr&lt;/span&gt;.Zero;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_lastPID = 0;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  &lt;span style="color:green;"&gt;// call the SDF because it&amp;#39;s not a P/Invoke - it&amp;#39;s a kcall
and this is less code&lt;/span&gt;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_myPID = (&lt;span style="color:blue;"&gt;uint&lt;/span&gt;)OpenNETCF.Diagnostics.&lt;span&gt;ProcessHelper&lt;/span&gt;.GetCurrentProcessID();&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
Interval = 100;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;You’ll notice here that to get the current process ID I’m
not just calling a P/Invoke, but instead calling into the Smart Device
Framework (SDF).  The reason for this is that GetCurrentProcessID isn’t a true
API, but is instead a macro that’s defined in the CE headers, and the value it
returns depends on the processor architecture of the device.  Rather than lay
out all of the code needed to determine this it’s a lot easier to just call a
function in the SDF.  Keeps the code smaller and less confusing.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;While we’re thinking about P/Invokes, we might as well
define the other two we do need:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;[&lt;span&gt;DllImport&lt;/span&gt;(&lt;span&gt;&amp;quot;coredll.dll&amp;quot;&lt;/span&gt;,
SetLastError = &lt;span style="color:blue;"&gt;true&lt;/span&gt;)]&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;extern&lt;/span&gt; &lt;span&gt;IntPtr&lt;/span&gt;
GetForegroundWindow();&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;[&lt;span&gt;DllImport&lt;/span&gt;(&lt;span&gt;&amp;quot;coredll.dll&amp;quot;&lt;/span&gt;,
SetLastError = &lt;span style="color:blue;"&gt;true&lt;/span&gt;)]&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;extern&lt;/span&gt; &lt;span style="color:blue;"&gt;uint&lt;/span&gt;
GetWindowThreadProcessId(&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;    &lt;/span&gt;&lt;span&gt;IntPtr&lt;/span&gt; hwnd, &lt;span style="color:blue;"&gt;out&lt;/span&gt; &lt;span style="color:blue;"&gt;uint&lt;/span&gt;
lpdwProcessId);&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To start and stop our watcher, we’ll expose a simple Enabled
property.  It’s job will be to start or stop our background worker thread.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;public
bool Enabled&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;{&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  get
{ return m_enabled; }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  set&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    if
(value == m_enabled) return;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    if
(value)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span&gt;Thread&lt;/span&gt; thread = new &lt;span&gt;Thread&lt;/span&gt;(WatcherThreadProc);&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
thread.IsBackground = true;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
thread.Start();&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    else&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
m_stopThread = true;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The only thing remaining is to implement the actual logic engine
of this class that does all of the work, which is all in a single method
running as the background thread:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
WatcherThreadProc()&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;{&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  &lt;span style="color:green;"&gt;// initialize some values&lt;/span&gt;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_stopThread = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_lastForeWindow = GetForegroundWindow();&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
GetWindowThreadProcessId(m_lastForeWindow, &lt;span style="color:blue;"&gt;out&lt;/span&gt;
m_lastPID);&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  &lt;span style="color:blue;"&gt;while&lt;/span&gt; (!m_stopThread)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    &lt;span&gt;IntPtr&lt;/span&gt; currentForeWindow = GetForegroundWindow();&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; (currentForeWindow != m_lastForeWindow)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span style="color:blue;"&gt;uint&lt;/span&gt; pid;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
GetWindowThreadProcessId(currentForeWindow, &lt;span style="color:blue;"&gt;out&lt;/span&gt;
pid);&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span style="color:green;"&gt;// window has changed - is it a new process?&lt;/span&gt;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span style="color:blue;"&gt;bool&lt;/span&gt; newProcess = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span style="color:blue;"&gt;if&lt;/span&gt; (pid != m_lastPID)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
{&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;       
newProcess = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;       
m_lastPID = pid;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
}&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span style="color:blue;"&gt;bool&lt;/span&gt; inMyProcess = (pid == m_myPID);&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
&lt;span style="color:blue;"&gt;if&lt;/span&gt; (WindowChanged != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
{&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;       
WindowChanged(newProcess, inMyProcess);&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
}&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;     
m_lastForeWindow = currentForeWindow;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    &lt;span&gt;Thread&lt;/span&gt;.Sleep(Interval);&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt; 
m_enabled = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;You can see that it runs on the period determined by the
Interval property.  Ever Interval, it checks the foreground Window.  If it has
changed, it then determines if the new foreground Window is in the same process
as the last.  Next it determines if the process that owns the foreground Window
is the same process that created the watcher class itself and finally it fires
off an event of there are any subscribers.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;That’s all there is to it.  Using the new class is very,
very simple.  It looks like this:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;WindowWatcher
watcher = &lt;span style="color:blue;"&gt;new&lt;/span&gt; WindowWatcher();&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;watcher.WindowChanged
+= WindowChangedHandler;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;…&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; WindowChangedHandler(&lt;span style="color:blue;"&gt;bool&lt;/span&gt;
processChanged, &lt;span style="color:blue;"&gt;bool&lt;/span&gt; inMyProcess)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;{&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  &lt;span style="color:blue;"&gt;if&lt;/span&gt;(processChanged)&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    Debug.WriteLine(&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;       
&lt;span&gt;&amp;quot;Window and Process changed - we {0} in our
app&amp;quot;&lt;/span&gt;, &lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span&gt;        &lt;/span&gt;inMyProcess ? &lt;span&gt;&amp;quot;are&amp;quot;&lt;/span&gt;
: &lt;span&gt;&amp;quot;are not&amp;quot;&lt;/span&gt;));&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  &lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  {&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;    Debug.WriteLine(&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;       
&lt;span&gt;&amp;quot;Window changed - we {0} in our app&amp;quot;&lt;/span&gt;,
&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span&gt;        &lt;/span&gt;inMyProcess ? &lt;span&gt;&amp;quot;are&amp;quot;&lt;/span&gt;
: &lt;span&gt;&amp;quot;are not&amp;quot;&lt;/span&gt;));&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;  }&lt;/p&gt;

&lt;p class="Code" style="margin:0in 0in 0.0001pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;As Compact Framework developers, and really even as general
mobile and embedded device developers, we have to get used to the fact that
Microsoft can’t reasonably think of every possible use-case or business challenge
we might face. What’s important is that they’ve generally provided us the tools
to implement solutions to just about any problem we run into.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In this case we needed to know information about not just
application state, but overall device state, and in less than 100 lines of code
we came up with a reasonable solution that didn’t require any onerous coding or
framework that we’d have to inject into all of our Forms.  As with many
problems like this, understanding the Win32 API and thinking outside the
managed-code box can usually get you a fairly simple solution.&lt;/p&gt;

&lt;/div&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=65787" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author></entry><entry><title>Exchanging Data using Windows Mobile, Windows Communication Foundation, .NET Compact Framework and Exchange 2007</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2008/06/09/exchanging-data-using-windows-mobile-windows-communication-foundation-net-compact-framework-and-exchange-2007.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2008/06/09/exchanging-data-using-windows-mobile-windows-communication-foundation-net-compact-framework-and-exchange-2007.aspx</id><published>2008-06-09T15:05:00Z</published><updated>2008-06-09T15:05:00Z</updated><content type="html">




&lt;div class="Section1"&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;Mark Arteaga&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;OpenNETCF
Consulting&lt;/p&gt;

&lt;p class="MsoNormal"&gt;June 2008&lt;/p&gt;
&lt;div class="Section1"&gt;&amp;nbsp;

&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" alt="" align="middle" border="0" /&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/Sample%20Code.zip"&gt;Download the Source&lt;/a&gt;&lt;span class=""&gt;&lt;/span&gt;&lt;br /&gt;
&lt;font color="#0066cc"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" alt="" align="middle" border="0" height="30" /&gt;&amp;nbsp;&lt;/font&gt;
&lt;a href="http://community.opennetcf.com/blogs/cf/200805/GDI_Performance.pdf" class="" title="Download the PDF" target="_blank"&gt;
&lt;/a&gt;&lt;font color="#0066cc"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF.pdf"&gt;Download the PDF&lt;/a&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Introduction&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Several new features have been added to .NET Compact
Framework 3.5that you as a developer can take advantage of in your applications. 
An overview of what is new is available on &lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb397835.aspx"&gt;&lt;span&gt;MSDN&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;.
One such feature is Windows Communication Foundation (WCF).  For an
introduction to Windows Communication Foundation, you should read &lt;span&gt;&lt;a href="http://community.opennetcf.com/articles/cf/archive/2007/11/29/an-introduction-to-wcf-for-device-developers.aspx"&gt;&lt;span&gt;Chris Tacke’s article&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;.  This article will focus on
“Store and Forward messaging” using Exchange Server 2007.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;There are two sample applications accompanying this
article.  The first sample is a typical Line of Business (LOB) application
where a central dispatcher notifies field workers of a new customer request. 
The second sample is a peer-to-peer application where users can share photos
they have taken with their Windows Mobile device. The techniques used in the
second example could easily be used to share documents and other payloads in an
enterprise scenario.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Prerequisites&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;Visual Studio 2008&lt;/span&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;&lt;/li&gt;

&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;Exchange 2007&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p class="MsoNormal"&gt;&lt;span&gt;For the device applications:&lt;/span&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;.NET Compact Framework 3.5&lt;/span&gt;&lt;/li&gt;

&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;Windows Mobile 5.0 or later&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p class="MsoNormal"&gt;&lt;span&gt;For the desktop application:&lt;/span&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;.NET Framework 3.5&lt;/span&gt;&lt;/li&gt;

&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;.NET Compact Framework 3.5 SDK&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Why E-Mail?&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;You are probably wondering “&lt;i&gt;why use email to transport
data?  Why not use an ASP.NET Web service and have the device connect to that
Web service?&lt;/i&gt;”The simple answer is addressability. Mobile devices are just
that – &lt;i&gt;mobile&lt;/i&gt;. They cannot guarantee a constant connection unless you
are within the walled garden of a corporate network, even then there may well
be connectivity black spots. Also, many enterprise scenarios leverage public
cellular networks, where not only is connectivity not guaranteed, but you face
the bigger challenges of uncontrollable DHCP leases and carrier network address
translation (NAT). In light of this, e-mail is a very compelling transport for
a number of reasons. Most people already use email and many enterprises have
already deployed Direct Push Email with Exchange so leveraging this mechanism
for custom applications requires no changes to existing infrastructure.  You
can assume that application data will be delivered to the user’s device using
Exchange Direct Push Email whether the user is behind the firewall or outside
the firewall.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Getting Things Done&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To use WCF with Exchange, all we do is add references to the
assemblies listed below to our device and desktop projects:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;Device Project&lt;/li&gt;&lt;/ul&gt;

&lt;ol style="margin-left:40px;"&gt;&lt;li&gt;Microsoft.ServiceModel.Channels.Mail
(.NET Compact Framework version)&lt;/li&gt;&lt;li&gt;Microsoft.ServiceModel.Channels.Mail.WindowsMobile&lt;/li&gt;&lt;li&gt;System.Runtime.Serialization&lt;/li&gt;&lt;li&gt;System.ServiceModel&lt;/li&gt;&lt;/ol&gt;







&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Symbol;"&gt;&lt;/span&gt;Desktop Project&lt;/li&gt;&lt;/ul&gt;

&lt;ol style="margin-left:40px;"&gt;&lt;li&gt;Microsoft.ServiceModel.Channels.Mail
(.NET Framework version)&lt;/li&gt;&lt;li&gt;Microsoft.ServiceModel.Channels.Mail.ExchangeWebService&lt;/li&gt;&lt;li&gt;System.Runtime.Serialization&lt;/li&gt;&lt;li&gt;System.ServiceModel&lt;/li&gt;&lt;/ol&gt;







&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;One thing to note is that the
Microsoft.ServiceModel.Channels.Mail.dll assemblies in the above lists are two
separate assemblies - one for the device and one the desktop.  We discuss this
a bit more in the &lt;span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Sharing_Code_Between"&gt;&lt;span&gt;Sharing Code Between Platforms&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; section below.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;We have also created two helper classes to make it easier to
use the mail channel to be able to send data between devices and desktop. 
These two classes are &lt;span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_WCFMessagingManager_Events"&gt;&lt;b&gt;&lt;span&gt;WCFMessagingManager&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;and &lt;span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_XMLSerializerWrapper"&gt;&lt;b&gt;&lt;span&gt;XmlSerializerWrapper&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;XmlSerializerWrapper&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To serialize and de-serialize your data, WCF requires an
object inherit from &lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.xmlobjectserializer.aspx"&gt;&lt;b&gt;&lt;span&gt;XmlObjectSerializer&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;.  Desktop developers can
use &lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;&lt;b&gt;&lt;span&gt;DataContractSerializer&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;however this
class is not available in the .NET Compact Framework.  Instead, we will simply create
an &lt;b&gt;XmlSerializerWrapper &lt;/b&gt;class which inherits from XmlObjectSerializer
and has an internal XmlSerialzier member variable:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:6pt;line-height:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public class&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; XmlSerializerWrapper&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; : &lt;span&gt;XmlObjectSerializer&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:6pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:6pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; XmlSerializer&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; m_serializer;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:6pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:6pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;br /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In the constructor, we create a new XmlSerializer of the
type we want to serialize as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
XmlSerializerWrapper(&lt;span&gt;Type&lt;/span&gt; type)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_serializer = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;XmlSerializer&lt;/span&gt;(type);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;We also override the WriteObject() and ReadObject() methods
which WCF calls to serialize and de-serialize our object as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; WriteObject(&lt;span&gt;XmlDictionaryWriter&lt;/span&gt;
writer, &lt;span style="color:blue;"&gt;object&lt;/span&gt; graph)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_serializer.Serialize(writer, graph);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;And to de-serialize as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public override object&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; ReadObject(&lt;span&gt;XmlDictionaryReader&lt;/span&gt;
reader)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
m_serializer.Deserialize(reader);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;If you want more information on this take a look at the
following article &lt;span&gt;&lt;a href="http://blogs.msdn.com/andrewarnottms/archive/2008/01/18/using-the-xmlserializer-as-an-xmlobjectserializer-with-wcf.aspx"&gt;&lt;span&gt;Using the XmlSerializer as an XmlObjectSerializer with WCF&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;&lt;a class="" title="_Toc200771317" name="_Toc200771317"&gt;&lt;/a&gt;&amp;nbsp;&lt;/h3&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772433" name="_Toc200772433"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;WCFMessagingManager&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;WCFMessagingManager is a class that makes it easier for
developers to send and listen for messages using WCF.  It derives from the
Messaging class available in this &lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc164240.aspx"&gt;&lt;span&gt;MSDN
article&lt;/span&gt;&lt;/a&gt;,&lt;/span&gt; which outlines creating a mobile chat system using the
Compact Framework and Windows Mobile.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The WCFMessagingManager class is a generic class that
provides the flexibility to accept any type of object to send.  With the
Dispatch Application we use the DispatchMessage type and with the Picture
Sharing application we use the PhotoData object.  We will discuss these classes
in more detail in the &lt;span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Dispatch_Application"&gt;&lt;span&gt;Dispatch Application&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; and &lt;span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Picture_Sharing_Application"&gt;&lt;span&gt;Picture Sharing
Application&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; sections.&lt;/p&gt;

&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Creating
a WCFMessagingManager&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To send our data objects we need to create our mail binding
objects.  On the desktop we create and ExchangeWebServiceMailBinding as
follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ExchangeWebServiceMailBinding&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; binding = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;ExchangeWebServiceMailBinding&lt;/span&gt;(&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;Uri&lt;/span&gt;(Properties.&lt;span&gt;Settings&lt;/span&gt;.Default.ExchangeServer), &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;NetworkCredential&lt;/span&gt;(Email,
Password));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;br /&gt;
And on the device we create a WindowsMobileMainBinding object as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowsMobileMailBinding&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt; binding = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;WindowsMobileMailBinding&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;You will notice that on the desktop, you have to specify an
Exchange server address and your network credentials for the email account.  This
data is used to poll the mail box for any messages sent with the appropriate
channel names.  On the Windows Mobile side you don’t have to provide
credentials since WindowsMobileMailBindingmonitors the mail in the Outlook
inbox on the local device.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To use the WCFMessagingManager class we create a new
instance of the object and pass in a few parameters as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WCFMessagingManager&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;lt;&lt;span&gt;PhotoData&lt;/span&gt;&amp;gt;
m_messagingManager;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_messagingManager = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;WCFMessagingManager&lt;/span&gt;&amp;lt;&lt;span&gt;PhotoData&lt;/span&gt;&amp;gt;(binding,&lt;span&gt;Settings&lt;/span&gt;.Default.IncomingChannel);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;When we create the WCFMessagingManager, we explicitly set
PhotoData as the type for the generic class and the for constructor parameters
we provide the MailBindingBase (which both WindowsMobileMailBinding and
ExchangeWebServiceMailBinding both inherit from) and the channel we would like
to listen on.The channel must be unique to every user using the application,
but you can share the same email address for sending messages.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In the constructor of WCFMessagingManager we first build an
IChannelFactory using the mail bindings as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a param collection for both the input channel and output
channel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BindingParameterCollection&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt; param = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;BindingParameterCollection&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Build the channel factory&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_channelFactory
= m_mailBinding.BuildChannelFactory&amp;lt;&lt;span&gt;IOutputChannel&lt;/span&gt;&amp;gt;(param);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_channelFactory.Open();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;We build the IChannelFactory using the MailBindingBase
object passed in and open the IChannelFactory.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Once the IChannelFactory is created, we create a listener
channel so we can listen to incoming messages.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Build the channel listeners&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_channelListener
= m_mailBinding.BuildChannelListener&amp;lt;&lt;span&gt;IInputChannel&lt;/span&gt;&amp;gt;(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MailUriHelper&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.CreateUri(m_channelNameListen, &lt;span&gt;&amp;quot;&amp;quot;&lt;/span&gt;), param);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;The channel name used is the channelNameListen parameter
passed in the constructor.&lt;/p&gt;

&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Sending
Messages&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;WCFMessagingManager exposes a method to send data using e-mail
as the transport, which is defined as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; Sends a message to the receiving end&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;param name=&amp;quot;recipient&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;param name=&amp;quot;body&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
SendMessage(&lt;span style="color:blue;"&gt;string&lt;/span&gt; recipient,&lt;span style="color:blue;"&gt;string&lt;/span&gt; channel, T body)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {...}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;The
SendMessage method is fairly straightforward,requiring three parameters.  The
first one, recipient, is the destination email address that the message will be
going to.  The channel parameter is the channel the destination will be
listening on.  The body parameter is the object that will be sent to the
destination.  Notice that the body parameter is of a generic type, so in the
case of Photo Sharing application, we will be sending a PhotoData object.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;The
implementation of SendMessage is also fairly straightforward:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Use the channel factory to create an output channel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IOutputChannel&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; outputChannel = m_channelFactory.CreateChannel(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; new &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;EndpointAddress&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;(&lt;span&gt;MailUriHelper&lt;/span&gt;.Create(channel,
recipient)));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Open the output channel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputChannel.Open();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a message to send via the channel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Message&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
message = &lt;span&gt;Message&lt;/span&gt;.CreateMessage(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageVersion&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.Default, UrnInternal,&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; body, m_xmlSerializerWrapper);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Send the message&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputChannel.Send(message);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Close the oubput channel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputChannel.Close();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:12pt 0cm 0.0001pt;"&gt;Using the IChannelFactory we created
in the constructor, we create a new IOutputChannel specifying an EndpointAddress.
The EndpointAddress requires an output channel (or the listening channel of the
destination) and the destination email address of the recipient.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:12pt 0cm 0.0001pt;"&gt;Once the IOutputChannel is created,
we create a Message (defined in System.ServiceModel.Channels) using the static
Message.CreateMessage method.  Here we pass in a MessageVersion (which we set
to default), a Urn, the T body, and the XmlSerializerWrapper which will handle
serializing and deserializing our body.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:12pt 0cm 0.0001pt;"&gt;When a message is sent, you will get
a message in your mail box with a cryptic subject as follows:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:12pt 0cm 0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:12pt 0cm 0.0001pt;"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;SM:v=3.5;CN=treochannel;ID=cbb5d3c798c84af3b1daf7615b780fb3;SD=633472436040000000;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:12pt 0cm 0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-top:12pt;"&gt;And the actual message will look
something like this&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-top:12pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;s:Envelope&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:red;"&gt;xmlns:a&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;=&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://www.w3.org/2005/08/addressing&lt;/span&gt;&amp;quot;&lt;span style="color:red;"&gt;xmlns:s&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://www.w3.org/2003/05/soap-envelope&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;s:Header&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;a:Action&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:red;"&gt;s:mustUnderstand&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;=&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;urn:photoMessage&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;a:Action&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;a:To&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:red;"&gt;s:mustUnderstand&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;=&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;net.mail://treochannel/#marteaga@opennetcf.com&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;a:To&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;s:Header&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;s:Body&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;s:Body&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;s:Envelope&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-top:12pt;"&gt;This XML is automatically created
by the System.ServiceModel.Channels.Message class.  In the case of a PhotoData
object it will be serialized and added in between the body tags:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-top:12pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;PhotoData&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:red;"&gt;xmlns:xsi&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;=&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/span&gt;&amp;quot;&lt;span style="color:red;"&gt;xmlns:xsd&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://www.w3.org/2001/XMLSchema&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Id&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;9873fd22-189f-4525-97a5-4572dbcd7ad0&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Id&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;FileName&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;/cf/200806/WCF Windows Mobile Exchange and NETCF_files/img002.jpg&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;FileName&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Latitude&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;43.6919&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Latitude&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Longitude&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;-79.5782&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Longitude&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;FileSize&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;6776&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;FileSize&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Base64Data&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;...&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Base64Data&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;PhotoData&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Listening
for Incoming Messages&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;WCFMessagingManagerexposes a BeginListening method which
starts a separate thread that listens for incoming messages in the background. 
The core implementation of the listening thread is as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Open the listener channel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_channelListener.Open();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Accept and open the inputCHannel&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_inputChannel
= m_channelListener.AcceptChannel();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_inputChannel.Open();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Message&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
message;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Calling IInputChannel.Receive will block until a message is
receive or until the inputChannel is closed&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(&lt;span style="color:blue;"&gt;true&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; message = m_inputChannel.Receive();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(message == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; T body = message.GetBody&amp;lt;T&amp;gt;(m_xmlSerializerWrapper);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; OnIncomingMessage(body);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; catch&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(&lt;span&gt;Exception&lt;/span&gt; e)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Raise the exception handler&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; OnListenException(e);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The first thing we do is open the IChannelListener we
created in the WCFMessagingManager constructor.  Using the IChannelListener we
create an IInputChannel using the AcceptChannel() method and then Open() the
IInputChannel.  Once all this is setup, we step into the while() loop and call
Receive() on the IInputChannel.  IInputChannel.Receive is a blocking call and
will not return until an incoming message is received or the IInputChannel.Close()
method is called.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When a message is received, we get the Body of the message
using the GetBody method (passing in our XmlSerializerWrapper) and then raise
the IncomingMessage event.  If there is an error receiving the message, the
ListenException event is raised to notify the user that something has gone
wrong.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To stop listening for incoming messages, WCFMessagingManager
exposes a StopListening method which will shut down all channels and threads.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_WCFMessagingManager_Events" name="_WCFMessagingManager_Events"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;WCFMessagingManager Events&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;WCFMessagingManager also comes with two events so a user can
be notified when a new message is received on the device or desktop
application.  These events are:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; Occurs when an incoming message is received&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public event &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;IncomingMessageEventHandler&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; IncomingMessage;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; Occurs when an error occurs in the listen thread&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public event &lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;ExceptionEventHandler&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
ListenException;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;These events are primarily called from the listening thread
discussed above.  These events are self explanatory and we will use them in the
sample applications discussed below.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772434" name="_Toc200772434"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771318" name="_Toc200771318"&gt;&lt;/a&gt;&lt;a class="" title="_Sharing_Code_Between" name="_Sharing_Code_Between"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;­Sharing Code Between Platforms&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;A common way to share code between Windows Mobile and
Desktop applications is to build an assembly targeting the .NET Compact
Framework.  Since .NET Compact Framework assemblies are re-targetable, they can
be used in full .NET Framework applications without being recompiled. 
Unfortunately this is not the case with WCF because the .NET Framework
implementation of Microsoft.ServiceModel.Channels.Mail.dll is vastly different
to its .NET Compact Framework counterpart.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Luckily, the main source code files can be shared between the
desktop and device projects by adding the files as ‘Links’.  The following
image shows the files shared for the Photo Sharing application:&lt;/p&gt;

&lt;p class="MsoNormal" style="text-align:center;" align="center"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image001.jpg" border="0" height="229" width="169" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772436" name="_Toc200772436"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771320" name="_Toc200771320"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200772435" name="_Toc200772435"&gt;&lt;/a&gt;&lt;a class="" title="_Dispatch_Application" name="_Dispatch_Application"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Dispatch Application&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt; Scenario&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The Dispatch Application is used where a central dispatcher sends
out new requests to field service workers.  The solution consists of a desktop
application sending messages to and receiving messages from a Windows Mobile
application using Exchange Server 2007.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772437" name="_Toc200772437"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771321" name="_Toc200771321"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Desktop Implementation&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The desktop application is the central dispatch controller and
sends new requests to the devices in the field.  The user interface is a very
simple implementation:&lt;/p&gt;

&lt;p class="MsoNormal" style="text-align:center;" align="center"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image002.jpg" id="Picture 12" border="0" height="300" width="366" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To send a message to and from the device we define a class
that will represent the data we are sending back and forth.  We define the business
object using the DispatchMessage class as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; Defines a dispatch message sent to field service workers&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; DispatchMessage&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; A unique identifier&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Guid&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
Id { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;;
}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; The current Status of the message&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;DispatchStatus&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; DispatchStatus { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; The customer name for the request&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public string&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
CustomerName { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;;
}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; A description of the request&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public string&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
Request { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;;
}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt; The destination address of the request&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public string&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
Address { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;;
}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The DispatchMessage object will be added in between the &lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Body&lt;/span&gt;
tags of the WCF message when sent and the XmlSerializerWrapper will handle
serializing and de-serializing the object.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When the application loads, it creates a new
WCFMessagingManager and starts listening for messages.  When a new message is required,
the user fills in the appropriate fields and sends it off to the destination by
clicking on the “New Dispatch Message” button.  The code then dispatches the
message using the following code:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//Create
the dispatch message&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;DispatchMessage&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; dm = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;DispatchMessage&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;dm.Address =
txtAddress.Text;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;dm.CustomerName
= txtCustomerName.Text;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;dm.DispatchStatus
= &lt;span&gt;DispatchStatus&lt;/span&gt;.SentToServiceRep;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;dm.Id = &lt;span&gt;Guid&lt;/span&gt;.NewGuid();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;dm.Request =
txtRequest.Text;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//Add
the dispatch message to the list&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;m_messagesSent.Add(dm);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;UpdateListbox();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//Send
the message&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-left:36pt;"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;m_messagingManager.SendMessage(txtServiceRep.Text,
&lt;span&gt;ChannelNames&lt;/span&gt;.ServerChannelName, dm);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-left:36pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When the IncomingMessage event is raised, we update the
listbox on the main form with an update status from the device using the
following:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt; void&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
m_messagingManager_IncomingMessage(&lt;span&gt;DispatchMessage&lt;/span&gt;
body)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.Invoke(&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;EventHandler&lt;/span&gt;(&lt;span style="color:blue;"&gt;delegate&lt;/span&gt;(&lt;span style="color:blue;"&gt;object&lt;/span&gt;
sender, &lt;span&gt;EventArgs&lt;/span&gt; ea)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; //find the message in the internal list&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
message = &lt;span style="color:blue;"&gt;from&lt;/span&gt; tmsg &lt;span style="color:blue;"&gt;in&lt;/span&gt;
m_messagesSent&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
tmsg.Id.Equals(body.Id)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
tmsg;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(message.Count() == 1)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Update the dispatch status&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; message.First().DispatchStatus = body.DispatchStatus;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //add the item to the list&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_messagesSent.Add(body);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;  &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; UpdateListbox();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772438" name="_Toc200772438"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771322" name="_Toc200771322"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Windows Mobile Implementation&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The Windows Mobile application listens for new customer
dispatch requests while out in the field.  The UI implementation again is very
simple and allows for the DispatchMessage object details to be displayed.&lt;/p&gt;

&lt;p class="MsoNormal" style="text-align:center;" align="center"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image003.jpg" id="Picture 15" border="0" height="320" width="241" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When a message first arrives on the device, it will
automatically respond with a ‘DeviceConfirmReceipt’ status:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
m_messagingManager_IncomingMessage(&lt;span&gt;DispatchMessage&lt;/span&gt;
body)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.Invoke(&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;EventHandler&lt;/span&gt;(&lt;span style="color:blue;"&gt;delegate&lt;/span&gt;(&lt;span style="color:blue;"&gt;object&lt;/span&gt;
sender, &lt;span&gt;EventArgs&lt;/span&gt; ea)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.statusBar1.Text
= &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;span&gt;&amp;quot;New
Message Received for {0}&amp;quot;&lt;/span&gt;,body.CustomerName);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Application&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.DoEvents();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.txtAddress.Text
= body.Address;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.txtCustomerName.Text
= body.CustomerName;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.txtRequest.Text
= body.Request;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.cmbStatus.Text
= body.DispatchStatus.ToString();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.txtId.Text
= body.Id.ToString();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(body.DispatchStatus == &lt;span&gt;DispatchStatus&lt;/span&gt;.SentToServiceRep)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//Respond with a confirm receipt&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;           
CreateAndSendMessage(txtAddress.Text, txtCustomerName.Text, &lt;span&gt;DispatchStatus&lt;/span&gt;.DeviceConfirmReceipt,
txtRequest.Text, txtId.Text);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;This will be displayed on the desktop application:&lt;/p&gt;

&lt;p class="MsoNormal" style="text-align:center;" align="center"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image004.jpg" id="Picture 17" border="0" height="298" width="364" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The field service rep will also have the option to change
the status to the following:&lt;/p&gt;

&lt;p class="MsoNormal" style="text-align:center;" align="center"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image005.jpg" border="0" height="106" width="236" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;This way the central location will always know what the
current status of the job is.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772439" name="_Toc200772439"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771323" name="_Toc200771323"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Enhancements&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The sample dispatch application could be enhanced to better
fit into an enterprise scenario.  For example, the addition of SQL Server to
store the dispatch requests, a list of field service reps currently in the
field and integration with GPS data.  You can also use SQL Replication to
actually store the data and have it synchronize the data, and WCF can be used
notify the application to initiate a sync.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772440" name="_Toc200772440"&gt;&lt;/a&gt;&lt;a class="" title="_Picture_Sharing_Application" name="_Picture_Sharing_Application"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Picture Sharing Application&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt; Scenario&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The Picture Sharing application allows users to share recently
taken photos with their friends by leveraging WCF and Exchange to send the photos. 
The sample consists of a Windows Mobile application running on two separate
devices and a desktop application.  &lt;/p&gt;

&lt;p class="MsoNormal"&gt;In this sample we are assuming that the application will be
used between friends that want to share recently taken pictures, but the same
concept can be used in a LOB type application.  For example, a field worker
wanting to get some advice on a component while out in the field could use an
application of similar architecture.  The worker can snap a picture, send it
back to the central dispatch location and the central dispatch location will
automatically call back to provide assistance.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772442" name="_Toc200772442"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771326" name="_Toc200771326"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Windows Mobile Implementation&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In the previous example we had the desktop application
initiating the messages to send to the devices.  In this scenario, the devices
will be initiating and will be sending the messages to a desktop application as
well as a secondary device.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The Windows Mobile application consists of two forms and uses
the WCFMessagingManager and XmlSerializerWrapper classes.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The use of WCFMessagingManager and XmlSerializerWrapper is
similar to the DispatchSample except in this sample we are sending a PhotoData
object instead of DispatchMessage object.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;We create our WCFMessagingManager as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowsMobileMailBinding&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt; binding = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;WindowsMobileMailBinding&lt;/span&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_messagingManager = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;WCFMessagingManager&lt;/span&gt;&amp;lt;&lt;span&gt;PhotoData&lt;/span&gt;&amp;gt;(binding,
m_config.IncomingChannel);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The PhotoData class is defined as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;PhotoData&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {  
&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Bitmap&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; m_bitmap = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; PhotoData(&lt;span style="color:blue;"&gt;string&lt;/span&gt; filename)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Hardcoded
to the toronto Congress Center&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.Latitude = 43.6919;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.Longitude = -79.5782;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set
the file name&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileName =
filename;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetProperties();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set
the id&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Id = &lt;span&gt;Guid&lt;/span&gt;.NewGuid();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; PhotoData()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public string&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Comment { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Guid&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Id { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public string&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; FileName { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public double&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Latitude { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public double&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Longitude { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public int&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; FileSize { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public string&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Base64Data { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;///&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Bitmap&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; GetBitmapImage()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{ ... }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;private void&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; SetProperties()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0cm 0cm 0.0001pt 36pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{ ... }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Here you can see that we have various properties such as
Comment, FileName, Latitude/Longitude of where the picture was taken, FileSize
and Base64Data.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When sending the message over the wire using WCF, we want to
make sure to convert the actual image to Base64 string.  We accomplish this
with the following helper method within PhotoData class:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
SetProperties()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(&lt;span&gt;File&lt;/span&gt;.Exists(FileName))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//Grab the byte data from the file&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;FileStream&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
fs = &lt;span&gt;File&lt;/span&gt;.Open(FileName, &lt;span&gt;FileMode&lt;/span&gt;.Open);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;byte&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;[]
data = &lt;span style="color:blue;"&gt;newbyte&lt;/span&gt;[fs.Length];&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
fs.Read(data, 0, data.Length);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
fs.Close();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//Set the file size&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
FileSize = data.Length;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;//convert the byte[] to base64&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
Base64Data = &lt;span&gt;Convert&lt;/span&gt;.ToBase64String(data);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;This method is called from the PhotoData(string) constructor
and the constructor automatically sets the appropriate properties within the
class.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;You may have noticed that PhotoData has two constructors,
the first taking a string parameter and the second taking no parameters.  The
reason for this is that XmlSerializer (used in XmlSerializerWrapper) requires a
parameter-less constructor to de-serialize the XML data.  So when an incoming
PhotoData object is received, XmlSerializer will automatically de-serialize the
data.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;There is also a public method in the class which returns a
Bitmap object to display on the destination.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Bitmap&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
GetBitmapImage()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(m_bitmap == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(Base64Data != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; byte&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;[]
imageData = &lt;span&gt;Convert&lt;/span&gt;.FromBase64String(Base64Data);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_bitmap = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;Bitmap&lt;/span&gt;(&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;MemoryStream&lt;/span&gt;(imageData));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
m_bitmap;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So on an incoming PhotoData object, displaying the image is
as simple as calling GetBitmapImage.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The UI of the Windows Mobile application is straight
forward.  Main form, is a very simple form using a PictureBox and two menu
items to take a new picture and to send the pictures.&lt;/p&gt;

&lt;p class="MsoNormal" style="text-align:center;" align="center"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image006.jpg" id="Picture 1" border="0" height="240" width="240" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To take the pictures we use the
Microsoft.WindowsMobile.Forms.CameraCaptureDialog which is available with
Windows Mobile 5 and later devices as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(&lt;span&gt;CameraCaptureDialog&lt;/span&gt; ccd = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;CameraCaptureDialog&lt;/span&gt;())&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(ccd.ShowDialog() == &lt;span&gt;DialogResult&lt;/span&gt;.OK)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentPhotoData = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;PhotoData&lt;/span&gt;(ccd.FileName);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentPhotoData.FileName = ccd.FileName;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pictureBox1.Image = &lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;Bitmap&lt;/span&gt;(CurrentPhotoData.FileName);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When the picture is taken, we set the PictureBox to display
the currently displayed image.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Sending a PhotoData object is also straight forward and we
simply need to call WCFMessageingManager.SendMessage as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Send the message to the device&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_messagingManager.SendMessage(m_config.SendToEmail,
m_config.OutgoingChannel, CurrentPhotoData);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Send the message to the desktop&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_messagingManager.SendMessage(m_config.SendToEmail,
m_config.OutgoingChannelDesktop, CurrentPhotoData);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;WCFMessagingManager will handle sending the PhotoData
objects to the appropriate email address and the corresponding channels those
emails should be listening to.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772443" name="_Toc200772443"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771327" name="_Toc200771327"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Desktop Implementation&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The desktop implementation primarily just listens for
incoming PhotoData objects and displays them.  The user interface consists of a
ListBox to display the current PhotoData objects in memory, a PictureBox to
display the image and a WebBrowser control to display a Virtual Earth map and a
push pin of where the picture was taken.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The following is a screen shot of the user interface:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image007.jpg" id="Picture 7" border="0" height="530" width="624" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When the WCFMessagingManager.IncomingMessage event is
handled by the main UI we want to update our UI appropriately as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.BeginInvoke(&lt;span style="color:blue;"&gt;new&lt;/span&gt;&lt;span&gt;EventHandler&lt;/span&gt;(&lt;span style="color:blue;"&gt;delegate&lt;/span&gt;(&lt;span style="color:blue;"&gt;object&lt;/span&gt;
sender, &lt;span&gt;EventArgs&lt;/span&gt; ea)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //find the message in the internal list&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
message = &lt;span style="color:blue;"&gt;from&lt;/span&gt; tmsg &lt;span style="color:blue;"&gt;in&lt;/span&gt;
m_messagesReceived&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
tmsg.Id.Equals(body.Id)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
tmsg;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(message.Count() == 0)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //add the item to the list&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_messagesReceived.Add(body);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; UpdateListbox();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The m_messagesRecevied variable is of type
List&amp;lt;string&amp;gt;and is used as the DataSource for the ListBox as follows:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; listBox1.DataSource = m_messagesReceived;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;On the ListBox.SelectedIndexChanged event, we display the
picture and a push pin within the Virtual Earth map to give a visual location
of where the image was taken.  We accomplish this using the following:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
(listBox1.SelectedIndex &amp;gt;= 0 &amp;amp;&amp;amp; listBox1.SelectedIndex &amp;lt;
m_messagesReceived.Count)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PhotoData&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
pd = m_messagesReceived[listBox1.SelectedIndex];&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Grab the photo data object and display the image&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;.pictureBox1.Image
=  pd.GetBitmapImage();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Show a push pin on the map of where the image was taken&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; executeScript(ClearPushpinsScript);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; executeScript(AddPushpinScript, pd.Id.ToString(), &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (pd.Comment == &lt;span style="color:blue;"&gt;null&lt;/span&gt; ? &lt;span&gt;&amp;quot;No
Comments&amp;quot;&lt;/span&gt; : pd.Comment.ToString()),&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pd.Latitude, pd.Longitude);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //center on the push pin&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; executeScript(SetCenter, pd.Latitude, pd.Longitude);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //zoom in on the push pin&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; executeScript(Zoom, 18);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772444" name="_Toc200772444"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771328" name="_Toc200771328"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Final Results&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The following are screen shots of a test run.  Here I took a
picture using a Palm Treo 700wx running Windows Mobile 5.0, sent it to the
desktop application as well as a Windows Mobile 6.1 Professional Emulator.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image008.jpg" id="Picture 10" border="0" height="240" width="240" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image009.jpg" id="Picture 13" border="0" height="556" width="366" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200806/WCF%20Windows%20Mobile%20Exchange%20and%20NETCF_files/image010.jpg" id="Picture 16" border="0" height="522" width="624" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772445" name="_Toc200772445"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771329" name="_Toc200771329"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Virtual Earth Integration on the
Desktop&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Integration with Virtual Earth came up as the PhotoData
object contained Latitude and Longitude values.  To integrate Virtual Earth
with the WinForms application, &lt;span&gt;&lt;a href="http://www.viavirtualearth.com/vve/Gallery/Winforms2.ashx"&gt;&lt;span&gt;WinForms Earth v2&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; from Via Virtual Earth was
leveraged.  A few updates had to be done to get things to work as the original
code was extremely out date.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To get a Virtual Earth map to load within a WinForms
application and to communicate with the Virtual Earth map through code, there
are a few things that need to be done.&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;An
local HTMLpage is required that will load up the Virtual Earth Map.  This HTMLfile
will also contain JavaScript functions that will be called from the .NET
application&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;ComVisible&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;(&lt;span style="color:blue;"&gt;true&lt;/span&gt;) &lt;/span&gt;Attribute must be added to your form. 
This can also be added to a class that will handle the communication but
between the .NET code and the HTMLdocument but for simplicity we added it to
the Form.&lt;/li&gt;&lt;li&gt;Interaction
from .NET to the HTMLdocument JavaScript code is done by calling
WebBrowser.Document.InvokeScript method which accepts the javascript method
name and the parameters for the method&lt;/li&gt;&lt;li&gt;Interaction
from HTMLdocument to .NET is done by using the JavaScript function
window.external.X where X represents your method name in your .NET Code.  This
method must be public.  See the original source for WinForms Earth V2 as this
has the sample there.&lt;/li&gt;&lt;/ol&gt;







&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;a class="" title="_Toc200772446" name="_Toc200772446"&gt;&lt;/a&gt;&lt;a class="" title="_Toc200771330" name="_Toc200771330"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;"&gt;Enhancements&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Some enhancements that can be done to the application would
be integrating GPS functionality with the Windows Mobile application (see the &lt;span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb158699.aspx"&gt;&lt;span&gt;GPS Sample&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; application available with Windows
Mobile SDK).  On the desktop side, you can have the PhotoData objects stored in
a SQLServer Compact Database and also integrate any incoming data with Flickr
or Facebook Photos.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:16pt;line-height:115%;"&gt;Conclusion&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;E-mail has been around for a long time, and e-mail was one
of the first applications implemented on mobile devices.  With Windows Mobile,
now that we have direct push email and .NET Compact Framework 3.5 we can
leverage email and the direct push functionality in our Windows Mobile
applications.  As developers it allows us to focus on our application and not
worry about how we are going to get data from point A to point B,C,E etc.  If
using Exchange is not possible with your scenario, you can always extend the WCF
functionality with something like XMPP, but that’s an entire article on its
own!&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=65472" width="1" height="1"&gt;</content><author><name>marteaga</name><uri>http://community.opennetcf.com/members/marteaga.aspx</uri></author></entry><entry><title>Native vs. Managed Code: GDI Performance</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2008/05/19/native-vs-managed-code-gdi-performance.aspx" /><link rel="enclosure" type="application/pdf" length="84906" href="http://community.opennetcf.com/articles/cf/attachment/65322.ashx" /><id>http://community.opennetcf.com/articles/cf/archive/2008/05/19/native-vs-managed-code-gdi-performance.aspx</id><published>2008-05-19T14:56:00Z</published><updated>2008-05-19T14:56:00Z</updated><content type="html">




&lt;div class="Section1"&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;May 2008&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;Chris Tacke&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;OpenNETCF
Consulting, LLC&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" alt="" align="middle" border="0" /&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200805/GDI_Performance.zip"&gt;Download the Source&lt;/a&gt;&lt;span class=""&gt;&lt;/span&gt;&lt;br /&gt;
&lt;font color="#0066cc"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" alt="" align="middle" border="0" height="30" /&gt;&amp;nbsp;&lt;/font&gt;
&lt;a href="http://community.opennetcf.com/blogs/cf/200805/GDI_Performance.pdf" class="" title="Download the PDF" target="_blank"&gt;
&lt;/a&gt;&lt;font color="#0066cc"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200805/GDI_Performance.pdf"&gt;Download the PDF&lt;/a&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;Introduction&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;I recently saw a post in the
public Compact Framework newsgroup&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=8&amp;amp;postid=65322#_ftn1" class="" name="_ftnref1" title="_ftnref1"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;[1]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;
that is fairly typical.  The poster stated that if you want speed and
performance for graphics, you should use native (meaning C or C++) code.  It’s
a general sentiment that I often read or hear – native code is faster than
managed code for XYZ operation, so don’t use managed code.  In most cases these
claims are being made by developers with little experience in managed
development and they rarely have any sort of empirical data to back up their
statement.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;I knew that I already had some code for measuring GDI
performance in native code that I wrote several years ago for testing and
tuning a Windows CE display driver, so I decided I’d dig it up and then create
a managed application that did the same operations and then compare the results
of the two with real evidence and put to rest this silly myth once again.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h1&gt;Native Code Device Test&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;/b&gt;Before diving into managed code to see how it would perform,
I needed to get the baseline test running in native code.  The code I had was a
pretty simple and straightforward test.  It creates an off-screen square bitmap
and device context (DC), fills it with a varying shade of grey, and then draws
two intersecting green ellipses centered in that square (see Figure 1).  The
test then repeats the fill and ellipse drawing 10,000 times, each time changing
the fill color and the ellipse boundaries to prevent the driver from being able
to cache anything and to provide a nice psychedelic pattern to watch as the
test runs. The general code loop can be seen in Listing 1 (the full code
accompanies this article).&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:31.5pt;margin-right:0in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;...&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;screenDC = GetWindowDC(NULL);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;bufferDC =
CreateCompatibleDC(screenDC);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;oldPen =
(HPEN)SelectObject(bufferDC, CreatePen(PS_NULL, 0, NULL));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;oldBrush =
(HBRUSH)SelectObject(bufferDC, CreateSolidBrush(RGB(0,255,0)));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;hBufferBmp =
CreateCompatibleBitmap(screenDC, BOX_WIDTH, BOX_HEIGHT);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;oldObject =
SelectObject(bufferDC, hBufferBmp);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;rect.top = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;rect.left = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;rect.right = BOX_WIDTH;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;rect.bottom = BOX_HEIGHT;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;for&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;(i = 0 ; i &amp;lt; GDI_ITERATIONS_PER_REPORT
; i++)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; width += xop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; height+= yop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt;((width
&amp;gt;= BOX_WIDTH) || (width &amp;lt;= 0))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        xop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt;((height
&amp;gt;= BOX_HEIGHT) || (height &amp;lt;= 0))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        yop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; r += rop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; g += gop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; b += bop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt;((r
&amp;gt; 254) || (r&amp;lt; 1))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        rop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt;((g
&amp;gt; 254) || (g&amp;lt; 1))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        gop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt;((b&amp;gt;
254) || (b&amp;lt; 1))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        bop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; boxBrush =
CreateSolidBrush(RGB(r, g, b));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; FillRect(bufferDC,
&amp;amp;rect, boxBrush);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; DeleteObject(boxBrush);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Ellipse(bufferDC, width,
height, BOX_WIDTH - width, BOX_HEIGHT - height);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; Ellipse(bufferDC, height,
width, BOX_WIDTH - height, BOX_HEIGHT - width);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; BitBlt(screenDC, left, top,
left + BOX_WIDTH, top + BOX_HEIGHT, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        bufferDC, 0, 0,
SRCCOPY);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt;...&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In the tests I ran, the loop executed for 10,000
iterations.  On the Windows Mobile 5.0 emulator that ships with Visual Studio
2008 running on my desktop PC this test executes at about 490 iterations per
second (one iteration being a fill, two ellipse draws and a blit to the
screen).  On a Windows Mobile 5.0 Dell Axim x51 (PXA270 processor) it achieves
about 250 iterations per second.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h1&gt;Compact Framework Device Test&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;/b&gt;The next step was to “port” the native code to managed
code.  The code is straightforward and most of the concepts in the native
application have direct parallels in managed code.  Listing 2 shows the essence
of the managed version of the loop code (again, the full source accompanies
this article).&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:27pt;margin-right:0in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;...&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Bitmap&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; backBuffer = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;Bitmap&lt;/span&gt;(BOX_WIDTH,
BOX_HEIGHT);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Brush&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; boxBrush;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Brush&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; ellipseBrush = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;SolidBrush&lt;/span&gt;(&lt;span&gt;Color&lt;/span&gt;.Green);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Graphics&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; screenGraphics =
f.CreateGraphics(); &lt;span style="color:green;"&gt;// Graphics.FromHdc(screenDC);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Graphics&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; backGraphics = &lt;span&gt;Graphics&lt;/span&gt;.FromImage(backBuffer);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;for&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; (i = 0; i &amp;lt;
GDI_ITERATIONS_PER_REPORT; i++)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    width += xop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    height += yop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt;
((width &amp;gt;= BOX_WIDTH) || (width &amp;lt;= 0))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        xop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt;
((height &amp;gt;= BOX_HEIGHT) || (height &amp;lt;= 0))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        yop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    r += rop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    g += gop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    b += bop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt;
((r &amp;gt; 254) || (r &amp;lt; 1))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        rop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt;
((g &amp;gt; 254) || (g &amp;lt; 1))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        gop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt;
((b &amp;gt; 254) || (b &amp;lt; 1))&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        bop *= -1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    boxBrush = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;SolidBrush&lt;/span&gt;(&lt;span&gt;Color&lt;/span&gt;.FromArgb(r, g, b));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
backGraphics.FillRectangle(boxBrush, 0, 0, BOX_WIDTH, BOX_HEIGHT);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    boxBrush.Dispose();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
backGraphics.FillEllipse(ellipseBrush, width, height, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;            BOX_WIDTH - 2 *
width, BOX_HEIGHT - 2 * height);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
backGraphics.FillEllipse(ellipseBrush, height, width, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;            BOX_WIDTH - 2 *
height, BOX_HEIGHT - 2 * width);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
screenGraphics.DrawImage(backBuffer, 0, 0);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:4pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;When I ran this test against Compact Framework 3.5 is was
rather surprised to see that on the Windows Mobile 5.0 emulator it only
achieved 425 iterations per second (15% slower than the native code) and on the
Axim it only achieved 210 iterations per second (19% slower than native code).&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h1&gt;Testing on the Desktop&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;/b&gt;To say the least, the results from the device tests
surprised me.  In my gut I had expected the managed code performance to be
within 5% of the native code – 10% at the outside – but to see 15-20% was
amazing.  I then wondered if it was maybe something specific to the Compact
Framework and that maybe we’d not see such a large disparity on the desktop. 
If I were asked to guess at the desktop results &lt;i&gt;before&lt;/i&gt; seeing the device
results I would have almost certainly said that the managed code results would
be within 5% of the native, but after seeing the results from the device I had
to actually run it and see.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;I modified both the device and desktop code slightly to get
single code bases for both languages that would compile for either target and
then re-ran the tests.  The managed code test achieved 825 iterations per
second on the same PC that the emulator was running on – so roughly twice as
fast.  The native code, however, surprised me again and this time it was more
“shock and awe” than mere surprise.  The native desktop version of the test
achieved 6200 iterations per second.  Yes, 625% faster than the managed code on
the same target.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h1&gt;Updating the Managed code&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;/b&gt;The managed code performed substantially worse than I
expected (especially on the desktop).  The question that still remains is
“why?”  What would account for this performance degradation?  I would suspect
that something like a call to Graphics.FillRectangle would just be a thin
wrapper around a P/Invoke to the Win32 FillRect call so does that mean the
performance problems we see are purely an artifact of the performance penalty
of crossing the P/Invoke boundary&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=8&amp;amp;postid=65322#_ftn2" class="" name="_ftnref2" title="_ftnref2"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;[2]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;? 
If so we should be able to remove the calls to the framework Drawing classes,
directly P/Invoke the GDI functions and get the same, or at least similar
results.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;I went back and reworked the managed code to be able to run
using only framework-provided drawing operations within the test loop or to
P/Invoke all of them.  I then re-ran the test on the Windows Mobile 5.0
Emulator and the Axim and got 455 and 225 iterations per second respectively. 
That’s a 7% speed improvement over using purely the framework-provided GDI
calls, and generally cut the difference between the native and managed tests in
half.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;This means that the penalty for crossing the P/Invoke
boundary is definitely part of the performance difference between native and
managed code in our tests, but it only accounts for about half of it.  I can’t
readily account for the other half, but if I were to make an educated guess
it’s likely because the framework is doing parameter and bounds checking on all
calls, which my P/Invokes aren’t doing, and it may be doing something different
for data marshaling to the native side as well.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;To be complete I then updated the code again so it would
compile and run on the desktop as well as the device (the P/Invoke declarations
are different between the two platforms).  What really surprised me here was
that using the P/Invokes on the desktop resulted in the managed test achieving
6150 iterations per second, or within 1% of the native test.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Obviously there’s something I don’t fully understand about
GDI under the full framework, but the updated tests show that managed code
certainly can perform just as fast as native code.  Since we at OpenNETCF tend
to focus on Windows CE and Windows Mobile, I decided to leave investigating the
huge disparity on the desktop to a later time.&lt;br /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;/b&gt;So I set out to gather some hard data and debunk a myth
about managed code being slow but I ended up confirming that managed code is
indeed slower, sometime &lt;i&gt;a lot&lt;/i&gt; slower, than native code - at least for
basic GDI operations.  Below is a summary table of my results as well as
results from another tech reviewer that ran tests on his devices for me (thanks
to Peter Nowak).&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp; &lt;br /&gt;&lt;/p&gt;

&lt;table class="MsoTableGrid" style="border:medium none;border-collapse:collapse;" cellpadding="0" cellspacing="0"&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:solid solid solid none;border-color:black black black -moz-use-text-color;border-width:1pt 1pt 2.25pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;Managed: Framework Calls&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:solid solid solid none;border-color:black black black -moz-use-text-color;border-width:1pt 1pt 2.25pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;Managed: P/Invoke Calls&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:solid solid solid none;border-color:black black black -moz-use-text-color;border-width:1pt 1pt 2.25pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;Native&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:solid solid solid none;border-color:black black black -moz-use-text-color;border-width:1pt 1pt 2.25pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;Native is &lt;i&gt;n&lt;/i&gt;% Faster (framework /
  P/invoke)&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;Desktop&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;2.66GHz Intel Core2 Duo&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;890&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;6150&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;6200&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;597% / 1%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:5.35pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;height:5.35pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:4pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;height:5.35pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="font-size:4pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;height:5.35pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="font-size:4pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;height:5.35pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="font-size:4pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;height:5.35pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="font-size:4pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;Device&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;Windows Mobile 5.0 Emulator&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;425&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;455&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;490&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;15% / 8%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;WinMo 5.0 &lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;Dell Axim x51&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;PXA270&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;210&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;225&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;250&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;19%  /  11%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;HTC TyTn*&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;Samsung 2442A&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;70&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;74&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;75&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;7% / 1%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;HTC P6300*&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;Samsung 2442&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;73&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;76&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;77&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;6% / 1%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;HTC Athena*&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;PXA270&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;118&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;119&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;128&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;9% / 8%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;HTC TyTn II*&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;Qualcomm 7200&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;155&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;168&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;178&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;15% / 6%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;HTC Sedna*&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;Qualcomm 7200&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;121&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;129&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;131&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;9% / 2%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color black black;border-width:medium 2.25pt 1pt 1pt;padding:0in 5.4pt;width:106.25pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;HTC Charmer*&lt;/p&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;OMAP850&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:1.25in;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;134&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83.15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;151&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:72.5pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;154&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color black black -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:126.9pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;15% / 2%&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;p class="MsoNormal" style="margin-left:1in;"&gt;&lt;span style="font-size:8pt;line-height:115%;"&gt;*  = Results from testing 1,000 iterations instead of 10,000&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;We can see that across the board managed code is always slower,
but that with a little extra effort and code we can squeeze a bit more
performance out of the managed code.  If you really need that extra speed it’s
probably worth the effort.  Making the changes on the desktop yields an
enormous improvement, but again there could be something fundamentally wrong
with the desktop test, so do some more investigation before just running wild
with the numbers I came up with.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So does this mean that native code is “superior” to managed
code and that you shouldn’t still consider using managed code for your
development projects?  I’m still going to adamantly answer “no.”  Managed code
is not the answer to all development problems, but neither is native code. 
Each has their place, their strengths and their weaknesses.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Consider the rapid development nature of managed code and
the nice variety of test and continuous integration tools available for managed
code developers.  It’s very difficult to make a business case that something
like a typical enterprise data collection and reporting application should be
developed using anything but managed code.  It will get you to market faster,
with lower cost, more features and less support headache.  What’s not to like?&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Similarly you’d be hard pressed to make a reasonable case
that something like an Ethernet driver should be written in anything but native
code.  The more difficult decisions are in the grey area between.  In these
cases you have to weigh the application requirements against your schedule,
budget and available resources.  Sure, the simple tests I ran here show that
for when it comes to raw throughput for simple GDI operations, native code is
faster but the human eye doesn’t really need anything faster than 30 frames per
second to see it as smooth – so is it really a problem?  What &lt;i&gt;else&lt;/i&gt; is
your application going to do?&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;If you’re making a flight simulator, then your app is all
about drawing and sure – native code would be the choice, but what about a card
game?  How about a drawing program or a text reader?  The point is that only
you can decide which is better for what you need to get done.  Hopefully this
article, instead of providing opinion and conjecture,  provides you another
piece of real information with hard data that can help you make that decision.&lt;/p&gt;

&lt;/div&gt;
&lt;div&gt;
&lt;hr align="left" /&gt;
&lt;div id="ftn1"&gt;

&lt;p class="MsoFootnoteText"&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=8&amp;amp;postid=65322#_ftnref1" class="" name="_ftn1" title="_ftn1"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span style="font-size:8pt;"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;[1]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:8pt;"&gt; microsoft.public.framework.compactframework&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div id="ftn2"&gt;

&lt;p class="MsoFootnoteText"&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=8&amp;amp;postid=65322#_ftnref2" class="" name="_ftn2" title="_ftn2"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span style="font-size:8pt;"&gt;&lt;span class="MsoFootnoteReference"&gt;&lt;span style="font-size:8pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;[2]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:8pt;"&gt; See my January 2008 article entitled “Performance
Implication of Crossing the P/Invoke Boundary”&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoFootnoteText"&gt;&lt;a href="http://community.opennetcf.com/articles/cf/archive/2008/01/31/performance-implications-of-crossing-the-p-invoke-boundary.aspx"&gt;&lt;span style="font-size:8pt;"&gt;http://community.opennetcf.com/articles/cf/archive/2008/01/31/performance-implications-of-crossing-the-p-invoke-boundary.aspx&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=65322" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Performance" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Performance/default.aspx" /><category term="P/Invoke" scheme="http://community.opennetcf.com/articles/cf/archive/tags/P_2F00_Invoke/default.aspx" /><category term="Native Code" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Native+Code/default.aspx" /><category term="GDI" scheme="http://community.opennetcf.com/articles/cf/archive/tags/GDI/default.aspx" /></entry><entry><title>Performance Implications of Crossing the P/Invoke Boundary</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2008/01/31/performance-implications-of-crossing-the-p-invoke-boundary.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2008/01/31/performance-implications-of-crossing-the-p-invoke-boundary.aspx</id><published>2008-01-31T16:09:00Z</published><updated>2008-01-31T16:09:00Z</updated><content type="html">




&lt;div class="Section1"&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:18pt;line-height:115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;January 2008&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Christopher Tacke&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;OpenNETCF Consulting, LLC&lt;/p&gt;&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" alt="" align="middle" border="0" /&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/PInvokePerf.zip"&gt;Download the Source&lt;/a&gt;&lt;span class=""&gt;&lt;/span&gt;&lt;br /&gt;
&lt;font color="#0066cc"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" alt="" align="middle" border="0" height="30" /&gt;&amp;nbsp;&lt;/font&gt;
&lt;a href="http://community.opennetcf.com/blogs/cf/200801/WCF/An%20Introduction%20to%20WCF%20for%20Device%20Developers.pdf" class="" title="Download the PDF" target="_blank"&gt;
&lt;/a&gt;&lt;font color="#0066cc"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary.pdf"&gt;Download the PDF&lt;/a&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;h1&gt;Introduction&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;A few months ago a colleague of mine and I were invited to
visit a potential customer to give them our thoughts and a expertise in the
design of a new control system.  The client makes machines that folds and fills
cartons – think of cereal boxes and the like – at amazingly high speeds.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;They had been using a proprietary system that they has
designed with no OS and they were reaching the limits of just how fast they
could run and how many sensors and the like that they could put on the Sercos
bus so they figured they could leverage Windows CE (readily available for the
controllers they already had) to bring out a new generation of machines with
better throughput, faster reset times and all of the sorts of things their
customers would love.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;After a full day of walking through wonderful UML diagrams
that detailed every last bit of how the process for their new system would work
a few things were very clear.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpFirst" style="text-indent:-0.25in;"&gt;1.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;They
definitely knew how to build boxes.  Seriously – it’s far more complex than I
imagined, and if I ever need a machine that folds cartons, these guys would
have my business.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpMiddle" style="text-indent:-0.25in;"&gt;2.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;They
spent a large amount of time thinking through a whole lot of the details of how
this new system architecture would work.  And when I say a large amount of
time, I mean probably more time than I’ve spent developing entire products. 
They had done serious due diligence here.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpLast" style="text-indent:-0.25in;"&gt;3.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;They
had no idea how managed code worked and a large majority of what they had done
was going to be unusable.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;True  story.  They had designed a large, very flexible,
pluggable, extensible, deeply-abstracted architecture for a machine that should
be able to fold several hundred or more cartons a minute and it had all been
designed around a managed code foundation.  These machines have motors, servos,
actuators, conveyors and all sorts of things that have to run in a very finely
tuned and orchestrated dance at a very high speed, and if any one item is in
the wrong place at the wrong time then the best case is that something gets
jammed or broken and worst case is a machine operator gets seriously injured.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The problem with their design was rooted in two fundamental
issues; the first being that managed code is not deterministic.  That means
that when any action happens (like a sensor sees a moving box) then the time
for a reaction to occur (an arm moves to make a fold) is unbounded.  If you’re
trying to make boxes that are all the same size and shape at any reasonable
rate of speed, you can imagine that having a fold in the same spot every time
might be fairly important. &lt;/p&gt;

&lt;p class="MsoNormal"&gt;Often you might hear the term “real-time” but the problem
with that term is the definition depends on the system you’re looking at.  A
system is real-time if the maximum latency (or jitter) of a reaction is less
than what you need for your system to operate.  If you’re calculating
trajectories for an air-to-air missile your definition of real-time is a whole
lot different than if you’re trying to measure the movement of a tectonic plate
in “real-time.”   &lt;/p&gt;

&lt;p class="MsoNormal"&gt;At any rate, we know that any environment with a garbage
collector, whether it’s C#, VB.NET running on Windows or Java running on Linux,
is not deterministic by its very nature, so there’s no point in beating on this
point too heavily.  If you want to know about the deterministic behaviors of
either Windows CE or managed code, there are good resources on the web to get
you well acquainted (and you’ll be seeing more from us in the coming months as
well).&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The other problem with their design using managed code,
however, is not so obvious (unless of course you read the title of this
paper).  If C# were somehow made deterministic, would it then be a good choice
for them?  We know that a large amount of what they need to do is going to
require Platform Invokes (or P/Invokes) and I instinctively felt that there was
going to be a problem with performance because of that.  Of course I had no
data to back that up and I knew of no specific papers or articles that
specifically looked at what the performance impacts of P/Invoke calls were, but
I knew in my gut that they were going to be a problem, so we went back to the
hotel, had dinner and a couple drinks, and I proceeded to put together some
test code to prove out what I knew deep-down just had to be true.&lt;/p&gt;

&lt;h1&gt;Test Theory&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;My original test code was far more complex that what we’ll
be looking at for this article.  In it I tried to do more realistic simulations
of what they would be doing in practice, including a lot of thread interactions
and driver calls.  For the most part a lot of those tests would just add
complexity and confusion to these tests so for this article I distilled the
problem down to just a few test points:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How
long does it take for a call originating in managed code to arrive in the
called native library?&lt;/li&gt;
&lt;li&gt;How
long does it take for the call to return back to the managed caller?&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &lt;/span&gt;Does
a callback perform any better than a returned value or parameter?&lt;/li&gt;
&lt;/ol&gt;



&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;To measure the first I decided that I would get the current
value of the performance counter right before the P/Invoke call and then in the
native library I would grab the value again as soon as the method was entered. 
To make the second and third tests easier, I would simply return the
performance counter value collected in the native method back to the managed
caller either directly as a return value or through a callback.  The managed
caller could then do some basic math and arrive at answers for all three
questions.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Of course the raw answers themselves are pretty useless.  If
you want better performance, all you need is a faster processor.  To really
make any use of these numbers, we need to do the same test in pure native code
doing the exact same steps and then do a comparison of the native and managed
results.  What is important is not the hard numbers, but the ratios or
percentages of a managed test to an analogous native test.&lt;/p&gt;

&lt;h1&gt;The Native Callee&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;Step one was to create the native library that would get
called by both the native and the managed clients.  Using the same library for
both tests eliminates it as a source of variability, and in this case is was
really simple.  I simply exported two functions – one that would return the
time it received a call through an output parameter and the other through a
callback.  The code is really simple:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
(*NATIVE_CALLBACK)(LARGE_INTEGER timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; LARGE_INTEGER g_li;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;extern&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span&gt;&amp;quot;C&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;__declspec&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;(&lt;span style="color:blue;"&gt;dllexport&lt;/span&gt;)
&lt;span style="color:blue;"&gt;void&lt;/span&gt; DirectCall(LARGE_INTEGER *timeReceived)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       &lt;span style="color:green;"&gt;// get the time&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       QueryPerformanceCounter(timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;extern&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span&gt;&amp;quot;C&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;__declspec&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;(&lt;span style="color:blue;"&gt;dllexport&lt;/span&gt;)
&lt;span style="color:blue;"&gt;void&lt;/span&gt; CallBack(NATIVE_CALLBACK callback)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       &lt;span style="color:green;"&gt;// get the time&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       QueryPerformanceCounter(&amp;amp;g_li);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       callback(g_li);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:14pt;line-height:115%;font-family:&amp;#39;Cambria&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h1&gt;Collecting Control Data&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;Step two was to gather some data to use as the “control” for
the experiment by writing a native client EXE that calls the native DLL and
receives back a value through both a return value and a callback.  TO make sure
I had a decent amount of data I ran 10,000 iterations of the test and output
the results to a CSV file so I could plot and analyze the data in Excel. 
Again, the code is very simple.  I opted to load the library dynamically to
replicate as close as possible what managed code would be doing:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; LARGE_INTEGER li1;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; LARGE_INTEGER li2;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; HANDLE hFile;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;char&lt;/span&gt;
line[500];&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
(*NATIVE_CALLBACK)(LARGE_INTEGER timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
(*DIRECTCALL)(LARGE_INTEGER *timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;typedef&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
(*CALLBACKFCN)(NATIVE_CALLBACK callback);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; CallbackProc(LARGE_INTEGER
timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; _tmain(&lt;span style="color:blue;"&gt;int&lt;/span&gt; argc, _TCHAR* argv[])&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       HINSTANCE hLib =
LoadLibrary(_T(&lt;span&gt;&amp;quot;NativeDLL.dll&amp;quot;&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       DIRECTCALL DirectCall
= (DIRECTCALL)GetProcAddress(hLib, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              _T(&lt;span&gt;&amp;quot;DirectCall&amp;quot;&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       CALLBACKFCN CallBack =
(CALLBACKFCN)GetProcAddress(hLib, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              _T(&lt;span&gt;&amp;quot;CallBack&amp;quot;&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       OpenLog();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       LARGE_INTEGER
timeReceived;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       WriteLog(&lt;span&gt;&amp;quot;point#, outDirect, backDirect, outCallback,
backCallback\r\n&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       &lt;span style="color:blue;"&gt;for&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; i = 0 ; i
&amp;lt; 10000; i++)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              QueryPerformanceCounter(&amp;amp;li1);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              DirectCall(&amp;amp;timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              QueryPerformanceCounter(&amp;amp;li2);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              sprintf(line, &lt;span&gt;&amp;quot;%d, %d, %d,&amp;quot;&lt;/span&gt;, i, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;                     timeReceived.LowPart
- li1.LowPart, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;                     li2.LowPart
- timeReceived.LowPart);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              WriteLog(line);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              QueryPerformanceCounter(&amp;amp;li1);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              CallBack(&amp;amp;CallbackProc);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       CloseLog();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       FreeLibrary(hLib);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       &lt;span style="color:blue;"&gt;return&lt;/span&gt; 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; CallbackProc(LARGE_INTEGER
timeReceived)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       QueryPerformanceCounter(&amp;amp;li2);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       sprintf(line, &lt;span&gt;&amp;quot;%d, %d\r\n&amp;quot;&lt;/span&gt;, timeReceived.LowPart -
li1.LowPart, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;              li2.LowPart -
timeReceived.LowPart);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       WriteLog(line);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;h1&gt;Collecting Compact Framework Data&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;The code for collecting the data from the managed
application is obviously the same basic idea as the native application.  Each
of the native APIs are called and the managed application calculates the times
and logs them to a file.  The app runs this set 10,000 times to get a good
sampling.  The meat of the logic is below – the full source is in the download
for this article.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;delegate&lt;/span&gt;
&lt;span style="color:blue;"&gt;void&lt;/span&gt; CallbackDelegate(&lt;span style="color:blue;"&gt;ulong&lt;/span&gt;
timeReceived);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt;
Test&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;ulong&lt;/span&gt;
start;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;ulong&lt;/span&gt;
recv;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;ulong&lt;/span&gt;
stop;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    CallbackDelegate
callbackDelegate;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span&gt;IntPtr&lt;/span&gt;
callbackPtr;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt;
&lt;span style="color:blue;"&gt;void&lt;/span&gt; Run()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; outDirect;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; outCallback;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; backDirect;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; backCallback;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        callbackDelegate = &lt;span style="color:blue;"&gt;new&lt;/span&gt; CallbackDelegate(CallbackProc);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        callbackPtr = &lt;span&gt;Marshal&lt;/span&gt;.GetFunctionPointerForDelegate(callbackDelegate);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        OpenLog(&lt;span&gt;&amp;quot;\\managedNoGC.csv&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        WriteLog(&lt;span&gt;&amp;quot;point#, outDirect, backDirect, outCallback,
backCallback\r\n&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        &lt;span style="color:blue;"&gt;for&lt;/span&gt; (&lt;span style="color:blue;"&gt;int&lt;/span&gt; i = 0; i
&amp;lt; 10000; i++)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;            RunOne(&lt;span style="color:blue;"&gt;out&lt;/span&gt; outDirect, &lt;span style="color:blue;"&gt;out&lt;/span&gt;
backDirect, &lt;span style="color:blue;"&gt;out&lt;/span&gt; outCallback, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;                &lt;span style="color:blue;"&gt;out&lt;/span&gt; backCallback);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;            WriteLog(&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;span&gt;&amp;quot;{0},{1},{2},{3},{4}\r\n&amp;quot;&lt;/span&gt;,
i, outDirect, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;                backDirect,
outCallback, backCallback));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        CloseLog();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt;
&lt;span style="color:blue;"&gt;void&lt;/span&gt; CallbackProc(&lt;span style="color:blue;"&gt;ulong&lt;/span&gt;
timeReceived)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
QueryPerformanceCounter(&lt;span style="color:blue;"&gt;out&lt;/span&gt; stop);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        recv = timeReceived;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt;
&lt;span style="color:blue;"&gt;void&lt;/span&gt; RunOne(&lt;span style="color:blue;"&gt;out&lt;/span&gt;
&lt;span style="color:blue;"&gt;int&lt;/span&gt; timeOutDirect, &lt;span style="color:blue;"&gt;out&lt;/span&gt;
&lt;span style="color:blue;"&gt;int&lt;/span&gt; timeBackDirect, &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;               &lt;span style="color:blue;"&gt;out&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt;
timeOutCallback, &lt;span style="color:blue;"&gt;out&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt;
timeBackCallback)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
QueryPerformanceCounter(&lt;span style="color:blue;"&gt;out&lt;/span&gt; start);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        DirectCall(&lt;span style="color:blue;"&gt;out&lt;/span&gt; recv);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
QueryPerformanceCounter(&lt;span style="color:blue;"&gt;out&lt;/span&gt; stop);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        timeOutDirect = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)(recv - start);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        timeBackDirect = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)(stop - recv);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
QueryPerformanceCounter(&lt;span style="color:blue;"&gt;out&lt;/span&gt; start);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
CallBack(callbackPtr);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        timeOutCallback = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)(recv - start);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        timeBackCallback = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)(stop - recv);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Since managed code also has the huge variable of the GC, I
also decided to rerun the test  with a background thread continually allocating
and throwing away data.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; ThreadProc()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    &lt;span style="color:blue;"&gt;while&lt;/span&gt;
(running)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;        garbage = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:blue;"&gt;byte&lt;/span&gt;[63000];&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;margin-bottom:0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Now if you’re paying close attention you’ll notice that our
timing code here is not identical to that in the managed code. 
QueryPerformanceCounter itself is a P/Invoke, so we’re inherently adding the
time for the return from that P/Invoke to our results.  Eliminating this effect
would take a bit of work that would make this test setup a lot more convoluted,
and we’re trying to keep this simple, but keep it in mind when looking at the
results later.&lt;/p&gt;

&lt;h1&gt;Results&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;Once I’d run all the tests, I imported the data files into
an Excel spreadsheet for analysis and plotting.  The following plots provide
comparative views of the times for each “segment” of the test (i.e. each of our
three initial questions.  Each plot has three data sets – the control (native)
data and then managed data run with and then without a background thread
generating garbage (and therefore garbage collection).  The plots show
performance counter ticks (elapsed time) on the Y axis and the sample number of
the X axis.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border:1pt solid windowtext;padding:1pt 4pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;margin-left:0.5in;margin-right:0.5in;"&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;text-align:center;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;" align="center"&gt;&lt;b&gt;&lt;u&gt;NOTE&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="border:medium none;padding:0in;text-align:justify;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;Unless otherwise noted, the results reported in the charts in this
section are in performance counter ticks.  The test device used was an iCOP
eBox-2300 with a 200MHz Vortex86 processor that reports a performance counter
frequency of 1,193,180 ticks per second.&lt;/p&gt;

&lt;/div&gt;
&lt;h2&gt;Outgoing Direct Call&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;In Figure 1 we see the times required to make a direct call
into the DirectCall method.  We can see that a vast majority of the times for
all three data sets appear to be about the same and very small. We’ll look at
the actual mean values later, but this plot shows some important points:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The
managed calls occasionally have gigantic outliers.  We have a couple calls that
took over 15,000 ticks (over 12 milliseconds on the test device).&lt;/li&gt;
&lt;li&gt;Even
the native code has some jitter (we see a maximum of 1024 ticks, or about 860
microseconds) but the jitter, or outlier variation from the mean, is much less
pronounced than the managed code.&lt;/li&gt;
&lt;li&gt;We
see the same outlier frequency whether or not we have GC occurring.&lt;/li&gt;
&lt;/ol&gt;



&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;So from this plot we see that managed code appears to
inherently increase the overall jitter of the system by over an order of
magnitude.  When you’re designing a system that must perform a task within a
certain time boundary, you must look at the worst-case scenarios for your
maximum speed, so just on this small sample of raw data we would say that we
could safely run native code over 15 times faster than managed (15955 / 1024). 
Of course this is assuming that the P/Invoke call is part of the time-critical
logic.&lt;/p&gt;

&lt;p class="MsoCaption"&gt;&lt;i&gt;&lt;b&gt;Figure 1&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/controlpanel/blogs/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary_files/image001.gif" height="446" width="614" alt="" /&gt;&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image001.gif"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image001.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Figure 2 is shows the same data but with the Y-axis rescaled
to show just the low-end mean data.  The interesting point that we see here is
that the average speed to make the call from managed code is about half the
speed of the native call.&lt;/p&gt;

&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&lt;i&gt;&lt;b&gt;Figure 2&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/controlpanel/blogs/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary_files/image002.gif" id="Picture 2" height="433" width="596" alt="" /&gt;&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image002.gif"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image002.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:13pt;line-height:115%;font-family:&amp;#39;Cambria&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h2&gt;Direct Call Return&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;In Figure 3 we look at the time required to return from a
method.  Again, it looks like the mean for the native and the managed tests are
about the same and very small, but we still see some critical points:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Both
the managed and native code have occasional outliers&lt;/li&gt;
&lt;li&gt;The
managed outliers are an order of magnitude larger than those from the native
code.&lt;/li&gt;
&lt;/ol&gt;


&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&lt;i&gt;&lt;b&gt;Figure 3&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/controlpanel/blogs/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary_files/image003.gif" height="472" width="650" alt="" /&gt;&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image003.gif"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image003.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Figure 4 again is the same data as Figure 3, but with the
Y-Axis rescaled.  You can see that the managed code appears to be slightly
faster on average (it looks like the “blue” area extends about 1 tick below the
green) but all three data sets seem to be about the same.&lt;/p&gt;

&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&lt;i&gt;&lt;b&gt;Figure 4&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/controlpanel/blogs/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary_files/image004.gif" id="Picture 3" height="391" width="538" alt="" /&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image004.gif"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image004.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:13pt;line-height:115%;font-family:&amp;#39;Cambria&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h2&gt;Returning Through a Callback&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;Figures 5 and 6 show the results for the callback times and
are the most interesting of the group.  Figure 5 is simply the same data as
Figure 3 but with the Y-Axis scaled to show just data with times below 600
ticks.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Right away we see the same trend as the earlier plots – that
the managed code produces outliers much greater in magnitude than the native
code.  What’s different here, though, is the frequency of those outliers. 
Instread of just a couple over the 10,000 sample data set, we see a dozen very
large outliers (with the GC data set) and still a lot more low-end variation
(all the spikes above the average but below around 3000 ticks).&lt;/p&gt;

&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&lt;i&gt;&lt;b&gt;Figure 5&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/controlpanel/blogs/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary_files/image005.gif" id="Picture 4" height="419" width="577" alt="" /&gt;&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image005.gif"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image005.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;If we zoom in on the low-end data, Figure 4 show some
interesting points as well.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The
average for the managed callbacks is substantially higher (turns out to be over
10 times slower as we’ll see later) than native callbacks.&lt;/li&gt;
&lt;li&gt;Managed
callbacks are &lt;u&gt;never&lt;/u&gt; as fast as a native callback&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&lt;/span&gt;GC
appears to have a larger impact on callbacks than anything else we’ve looked at&lt;/li&gt;
&lt;/ol&gt;



&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoCaption" style="page-break-after:avoid;"&gt;&lt;i&gt;Figure 6&lt;/i&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;img src="http://community.opennetcf.com/controlpanel/blogs/Performance%20Implications%20of%20Crossing%20the%20PInvoke%20Boundary_files/image006.gif" id="Picture 5" height="404" width="556" alt="" /&gt;&lt;/p&gt;

&lt;span style="font-size:11pt;line-height:115%;font-family:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image006.gif"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200801/PInvoke/image006.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br style="page-break-before:always;" /&gt;
&lt;/span&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size:13pt;line-height:115%;font-family:&amp;#39;Cambria&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h2&gt;Summary Data&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;Below are tables that summarize the collected data.  The
upper pair show statistics for the direct call and return.  The lower pair show
the callback (call and return statistics).  You can see that the number
solidify the perceptions we got from looking at the plots.  Making a P/Invoke
call does indeed take almost twice as long as the comparable native call. And
the return is even 20-30% slower.&lt;/p&gt;

&lt;table class="MsoNormalTable" style="width:503.6pt;margin-left:4.55pt;border-collapse:collapse;" cellpadding="0" cellspacing="0"&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="padding:0in 5.4pt;width:59pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td colspan="3" style="border-style:solid;border-color:windowtext black windowtext windowtext;border-width:1pt;padding:0in 5.4pt;width:224.8pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="color:black;"&gt; outDirect&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td colspan="3" style="border-style:solid solid solid none;border-color:windowtext black windowtext -moz-use-text-color;border-width:1pt 1pt 1pt medium;padding:0in 5.4pt;width:219.8pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="color:black;"&gt; backDirect&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Native&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed- No GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed - with GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Native&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed- No GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed - with GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border:1pt solid windowtext;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Min&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;20&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;22&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;11&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;11&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Max&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;15761&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;15955&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;12&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;544&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16117&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Mean&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;17&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;33&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;32&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;11&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;14&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Median&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;17&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;28&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;28&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;11&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="border-style:none solid;border-color:-moz-use-text-color windowtext;border-width:medium 1pt;padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Mode&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;17&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;28&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;28&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="border:1pt solid windowtext;padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;% of Native&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;100.0%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;51.5%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;53.2%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;100.0%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;79.9%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;69.8%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="padding:0in 5.4pt;width:59pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:83pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="padding:0in 5.4pt;width:59pt;height:15pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td colspan="3" style="border-style:solid;border-color:windowtext black windowtext windowtext;border-width:1pt;padding:0in 5.4pt;width:224.8pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="color:black;"&gt; outCallback&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td colspan="3" style="border-style:solid solid solid none;border-color:windowtext black windowtext -moz-use-text-color;border-width:1pt 1pt 1pt medium;padding:0in 5.4pt;width:219.8pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:center;line-height:normal;" align="center"&gt;&lt;span style="color:black;"&gt; backCallback&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;&lt;br /&gt;&lt;/td&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Native&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed- No GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed - with GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Native&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed- No GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Managed - with GC&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border:1pt solid windowtext;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Min&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;15&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;13&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;12&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;135&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;137&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Max&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;907&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;15207&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;870&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;506&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16295&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16779&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Mean&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;18&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;19&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;14&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;190&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;271&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15pt;"&gt;
  
&lt;td style="border-style:none solid solid;border-color:-moz-use-text-color windowtext windowtext;border-width:medium 1pt 1pt;padding:0in 5.4pt;width:59pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Median&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;18&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;15&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;15&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;14&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;165&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;245&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="border-style:none solid;border-color:-moz-use-text-color windowtext;border-width:medium 1pt;padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;Mode&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;18&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;16&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;14&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;164&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;243&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 
&lt;tr style="height:15.75pt;"&gt;
  
&lt;td style="border:1pt solid windowtext;padding:0in 5.4pt;width:59pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="color:black;"&gt;% of Native&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;100.0%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:85.35pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;97.4%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:95.7pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;116.3%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:43.75pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;100.0%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:83pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;7.5%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  
&lt;td style="border-style:none solid solid none;border-color:-moz-use-text-color windowtext windowtext -moz-use-text-color;border-width:medium 1pt 1pt medium;padding:0in 5.4pt;width:93.05pt;height:15.75pt;"&gt;
  
&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-align:right;line-height:normal;" align="right"&gt;&lt;span style="color:black;"&gt;5.2%&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;h1&gt;Analyzing the Data&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;So now we have a whole lot of data.  Data is fine, but what
we really need is information.  Looking at these results raises more than a
couple questions that we can’t readily answer without access to the CLR
itself.  I don’t have access to that kind of information, but I &lt;u&gt;do&lt;/u&gt; have
access to people who do, so I sent off some questions to the developer who owns
the marshalling code for the Compact Framework to see if we could get some
answers.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To his credit he did a lot of footwork on this, injecting
stubs into the CLR and looking at outputs from the JIT compiler.  He sent me
several excellent explanations for several question complete with assembly
code. As a managed developer (and even as a native developer) looking at
assembly is like looking at a gorgon and we really only need to know the
general answers, so I’ll save you the petrification and summarize in somewhat
less technical terms.&lt;/p&gt;

&lt;h2&gt;Why is the P/Invoke call half the speed of the native call?&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;The managed call doesn&amp;#39;t directly call the native method. 
Instead it calls into a JITted stub method that must perform some overhead
routines such as calls to determine GC Preemption status (to determine if a GC
is pending and we need to wait).  It is also possible that some marshalling
code will get JITted into the stub as well. This all takes time.  Also keep in
mind (as pointed out back in the “Collecting Compact Framework Data” section
earlier) that the managed test itself is actually timing the return from the
QueryPerformanceCounter (QPC) P/Invoke as well.&lt;/p&gt;

&lt;h2&gt;Why is the direct return 20-30% slower in managed?&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;Just like for the outbound call, the return in managed code
also includes a JITted stub that does some GC housekeeping to see if a GC is
pending plus we still have our QPC return time which slows the managed test. &lt;/p&gt;

&lt;h2&gt;Why are callbacks so crazy expensive in managed code?&lt;/h2&gt;

&lt;p class="MsoNormal"&gt;The deep answer to this is a complex answer complete with a
lot of assembly code that no reasonable developer really wants to read.  What
it boils down to, though, is this:&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The IntPtr returned by GetFunctionPointerForDelegate is not
really the pointer for the JITted callback.  It&amp;#39;s actually a pointer to a stub
that does some additional marshaling.  That stub in turn calls several
different functions down in mscoree, so the route is not straight and your call
stack for the callback itself is fairly deep.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;These calls check to see if we&amp;#39;re marshaling managed types,
packages and loads any arguments into buffers, makes the call and then packages
and marshals any return value.  Throughout this process the CLR is also doing
bookkeeping on the thread states, checking and adjusting GC preemption status,
looking for events and exceptions and potentially sending out debugger and/or
profiler information.  During all of this locks are getting acquired and
released and memory is getting allocated, so a GC can potentially be triggered
during the process as well.  &lt;/p&gt;

&lt;p class="MsoNormal"&gt;So a whole lot more is going on that simply jumping
execution to the callback function address as happens in native code.&lt;/p&gt;

&lt;h2&gt;Why is the directcall in 2x slower than native, but the call in for the
callback is about the same as native?  &lt;/h2&gt;

&lt;p class="MsoNormal"&gt;This one is baffling and without some really deep
investigation with a native profiler it difficult to say exactly what is
happing.  We would have expected the results to be the same.  There may be some
issues with code alignment, memory controller caching or something else that
isn’t obvious that is affecting this result.  For now it remains a mystery but
it’s likely to be an artifact of the environment, not the code itself.&lt;/p&gt;

&lt;h2&gt;What accounts for the diff between the two managed callbacks?  &lt;/h2&gt;

&lt;p class="MsoNormal"&gt;We see that individually they have a pretty solid mean, yet
they differ by 40%.  Why?  And what’s with the “steps” in the data?  The start
the same – is the “higher” level due to GC activity.  Does that make sense that
the “with GC” line would hop up after a short period and stay, since we’re
creating garbage as fast as we can?  If that’s so, then why does the “no GC”
hop up to about the same level and then stay there for a period before dropping
back down?&lt;/p&gt;

&lt;p class="MsoNormal"&gt;These are all reasonable questions and unfortunately without
a ton of work with both native and managed profilers the only thing we can do
is make educated guesses.  My guess is that the difference is that the
additional thread doing lots of allocation is contending for the same memory
allocation locks that the callback &amp;quot;goo&amp;quot; is using, and it&amp;#39;s the
contention for these locks that&amp;#39;s causing the callback to take longer.  We
might have some thread context switching that is being done in one case and not
the other.  Still your guess is probably as good as mine, and it’s not likely
that we’ll have a definitive answer soon (if ever), but I don’t think we really
need one.  The lesson we’re really interested is that the managed callbacks are
an order of magnitude slower than native callbacks.  A small jitter on exactly
how much isn’t terribly important in the overall scheme of things.&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p class="MsoNormal"&gt;So what have we learned here?  I’d say we can sum it up in a
few points:&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpFirst" style="text-indent:-0.25in;"&gt;1.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i&gt;Managed
callbacks, while extremely useful in some cases, are an order of magnitude
slower than native callbacks. &lt;/i&gt; &lt;br /&gt;
It’s probably advisable to not rely heavily on them or purposely architect a
solution to use callbacks if it can be avoided.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpMiddle" style="text-indent:-0.25in;"&gt;2.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i&gt;Managed
P/Invoke calls are slower than native method calls&lt;/i&gt;.&lt;br /&gt;
While the exact amount can vary, and the difference is small, the fact remains
that a P/Invoke is slower.  If you’re doing work where time is critical it’s
important to keep this in mind.  &lt;/p&gt;

&lt;p class="MsoListParagraphCxSpLast" style="text-indent:-0.25in;"&gt;3.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i&gt;Managed
code has a lot of jitter that must be considered in any solution&lt;/i&gt;.&lt;br /&gt;
The nature of managed code means that we have a garbage collector doing stuff
for us in the background, and when it does it’s work, the performance of other
threads is impacted and impacted severely. This isn’t just true for C# or
VB.NET. Any runtime with a collection mechanism (which includes Java) is going
to have this problem.  This means that if you have deterministic constraints in
your solution, they either need to have a lot of room for sway  or you need to
be using native code.  &lt;/p&gt;

&lt;p class="MsoNormal"&gt;I specifically not using the term “real-time” here because
almost all code needs some level of determinism.  When a user clicks a button
in your app, if it takes 30 seconds to respond that’s still unacceptable, so
you do have some deterministic requirement. If you’re measuring the real-time
speed of continental drift, a few seconds probably isn’t going to matter much. 
However if you’re trying to run a precision machine tool in a factory, a
hundred milliseconds can easily mean a ruined part or broken tool.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The point is that you need to understand your solutions
requirements and understand the limitations of the code you’re writing.  Don’t
dismiss managed code out-of-hand because of some general (often incorrect)
perception that it’s slow and likewise don’t architect it into a solution with
tight time requirements just because it’s the environment you know.  Both good
and bad code can be written in any language and the difference is usually
knowledge and experience.  The hope is that now you have a little more of that
and we can all try not to add to the large pool of bad code out there.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;/div&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=49278" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Performance" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Performance/default.aspx" /><category term="P/Invoke" scheme="http://community.opennetcf.com/articles/cf/archive/tags/P_2F00_Invoke/default.aspx" /></entry><entry><title>An Introduction to WCF for Device Developers</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/11/29/an-introduction-to-wcf-for-device-developers.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/11/29/an-introduction-to-wcf-for-device-developers.aspx</id><published>2007-11-29T19:55:00Z</published><updated>2007-11-29T19:55:00Z</updated><content type="html">




&lt;div class="Section1"&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:20pt;"&gt;An Introduction to WCF for Device
Developers&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Chris Tacke&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;OpenNETCF Consulting, LLC&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;November, 2007&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" alt="" align="middle" border="0" /&gt;
&lt;a href="http://www.opennetcf.com/downloads/download.aspx?s=WCF_CF" class="" title="Download the Source" target="_blank"&gt;
&lt;font color="#0066cc"&gt;Download the Source Code&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;
&lt;font color="#0066cc"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" alt="" align="middle" border="0" height="30" /&gt;&amp;nbsp;&lt;/font&gt;
&lt;a href="http://community.opennetcf.com/blogs/cf/200711/WCF/An%20Introduction%20to%20WCF%20for%20Device%20Developers.pdf" class="" title="Download the PDF" target="_blank"&gt;
&lt;font color="#0066cc"&gt;Download the PDF&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;u&gt;Introduction&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;With the release of Visual Studio 2008 to MSDN subscribers last week, I
decided that it was probably safe enough to install the tool and start using
it, plus I’m working on a large project where we’re soon going to need to be
able to communicate between a PC and a CE device.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Conceptually (and at only a very high level) I had an idea what Windows
Communication Foundation (WCF) is and my guess was that it could be used to
help solve the problem at hand, which is to generate some form of remoting
capability.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Of course I’d never actually created anything that used WCF, nor even
looked at WCF code except in some conference sessions, so the first step was to
head to the bookstore.  I picked up &lt;i&gt;Inside Windows Communication Foundation&lt;/i&gt;
from Microsoft Press and tried to give it a read.  As is typical for me, I
found most of it analogous to listening to a white noise machine.  It did
little to further my understanding of the subject, but left me annoyed and
tired.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;In all fairness I can’t say it’s a bad book, I just learn far better
from concrete examples and hand-on work than I do from reading about doing
something.  Chapters 6 and 7 which cover Channels actually was interesting and
useful and I actually read them rather than skimming.  Chapter 6 gave me enough
to say that the $40 I spent on it was worth the investment.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;So once I was done with the book and a couple beers, I decided it was
time to roll up my sleeved and start searching the web for some concrete
examples so I could walk through some code in a debugger and learn by breaking
stuff. &lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Little did I know that while there’s a lot of talk about WCF, finding a
simple example that comes complete with source code for both ends is not a
trivial task.  This is especially true when it comes to WCF for devices – there
simply is no full sample (that I could find anyway) that explained how to go
from nothing but Studio to two devices talking to one another, step by step,
with all the code and directions needed.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;So after a day and a half of stumbling around and cussing, I finally
ended up with something worked and that probably should have taken only an hour
to develop.  This white paper is a collection of the knowledge I gained, and
that single source of a WCF sample that some other developer is now, or will be
looking for in the near future.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;u&gt;Requirements&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Before you get started, make sure that you have everything tool-wise
that you’re going to need. &lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpFirst" style="margin-bottom:0.0001pt;text-indent:-0.25in;line-height:normal;"&gt;1.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;i&gt;Visual Studio 2008 (used to be called Orcas) RTM&lt;/i&gt;.  I downloaded
mine from MSDN. If you got yours elsewhere, then your mileage may vary through
this article.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpMiddle" style="margin-bottom:0.0001pt;text-indent:-0.25in;line-height:normal;"&gt;2.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;i&gt;Power Toys for .NET Compact Framework 3.5 CTP (September 2007)&lt;/i&gt;. This
one wasn’t obvious until I’d done a fair bit of searching.  You *will* need it,
so download and install it now.  The current link is &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=C8174C14-A27D-4148-BF01-86C2E0953EAB&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=C8174C14-A27D-4148-BF01-86C2E0953EAB&amp;amp;displaylang=en&lt;/a&gt;
but if you’ve been browsing Microsoft’s site for years like I have, you know
that that link may be dead next week, so search for title text if it fails.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpMiddle" style="margin-bottom:0.0001pt;text-indent:-0.25in;line-height:normal;"&gt;3.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;i&gt;A Windows Mobile 5.0 device&lt;/i&gt;.  In theory you should be able to use
any device that is supported by CF 3.5 (Windows CE 5.0 or 6.0 or WM 5.0 or
6.0), but I used an Axim x51.  I can say that I tried for some time to get them
WM 5.0 emulator working and failed, so you should at least start with a
physical device to remove that variable.&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpLast" style="margin-bottom:0.0001pt;text-indent:-0.25in;line-height:normal;"&gt;4.&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;i&gt;Windows XP development environment&lt;/i&gt;. While this isn’t necessarily
a requirement, I’m running XP, not Vista, so if there are any UAC steps that
are needed to get this working you’re not going to see them in this article. 
If you’re using Vista, I wish you luck.  Please post any necessary deviations
as comments.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;u&gt;The PC-side WCFServer application&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;To make things fairly simple we’re going to use a transport shipped
with WCF for devices and set up the server application to run on the PC (sure I
need the reverse in my target solution, but as Bill Murray said in What About
Bob – baby steps).&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;So the first thing we need is to create a service that does something
on the desktop.  We’re not going to go overboard and make it complex, we’re
going to have a single function that takes in two integers and returns the sum
of them.  My thinking is that once you see that working, getting more complex
stuff working is simply additional baby steps on top of that.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;So first, create a desktop Console application (if you were in a rush
and already created a WinForms app before you got this far in the article,
delete the Form and change the project type in the Project Properties just like
I ended up doing when I was creating this app).&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Add the following reference to the project:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:0.5in;line-height:normal;"&gt;System.ServiceModel&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now add a new Class (well it will be an interface, but using the Add Class
menu item and then changing the code is less clicking) document named
ICalculator and replace its code with the code below.  This is the interface
that defines the contract our service exposes.  It should all be self
explanatory, so I won’t bore you with a walk-through.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System.ServiceModel;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;namespace&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
OpenNETCF.WCF.Sample&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;[&lt;span&gt;ServiceContract&lt;/span&gt;(Namespace = &lt;span&gt;&amp;quot;http://opennetcf.wcf.sample&amp;quot;&lt;/span&gt;)]&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;interface&lt;/span&gt;
&lt;span&gt;ICalculator&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
[&lt;span&gt;OperationContract&lt;/span&gt;]&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; Add(&lt;span style="color:blue;"&gt;int&lt;/span&gt; a, &lt;span style="color:blue;"&gt;int&lt;/span&gt; b);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now we need to create an implementation of that interface to expose as
our actual service.  Add another Class to the project called CalculatorService
and overwrite the generated code in the document with the code below.  Again,
it’s not rocket science, so we’re not going to cover what it does.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;namespace&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
OpenNETCF.WCF.Sample&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span&gt;CalculatorService&lt;/span&gt; : &lt;span&gt;ICalculator&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt; Add(&lt;span style="color:blue;"&gt;int&lt;/span&gt; a, &lt;span style="color:blue;"&gt;int&lt;/span&gt; b)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;quot;Received &amp;#39;Add({0}, {1})&amp;#39; returning {2}&amp;quot;&lt;/span&gt;,
a, b, a + b));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; a + b;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;The last remaining piece of our service app is the logic that actually
creates an instance of our CalculatorService implementation and exposes it. 
This code is a little more complex (though not a whole lot), so we will look at
what it’s doing, but first, overwrite all the code in your existing Program.cs
file with the following code:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System.ServiceModel;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System.ServiceModel.Description;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
System.Net;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;namespace&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
OpenNETCF.WCF.Sample&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span&gt;Server&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;       
{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; hostIP = &lt;span&gt;Dns&lt;/span&gt;.GetHostEntry(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Dns&lt;/span&gt;.GetHostName()).AddressList[0].ToString();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;#if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
CLIENT_DISCOVERY_BUILD&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;Uri address = new Uri(string.Format(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;&amp;quot;http://localhost:8000/calculator&amp;quot;,
hostIP));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;#else&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Uri&lt;/span&gt; address = &lt;span style="color:blue;"&gt;new&lt;/span&gt;
&lt;span&gt;Uri&lt;/span&gt;(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;span&gt;&amp;quot;http://{0}:8000/calculator&amp;quot;&lt;/span&gt;,
hostIP));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;#endif&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;ServiceHost&lt;/span&gt; serviceHost = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;ServiceHost&lt;/span&gt;(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span&gt;CalculatorService&lt;/span&gt;),
address);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:green;"&gt;// Add a service endpoint&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;serviceHost.AddServiceEndpoint(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span&gt;ICalculator&lt;/span&gt;),&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;BasicHttpBinding&lt;/span&gt;(),&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;quot;Calculator&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;#if&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
CLIENT_DISCOVERY_BUILD&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;// Enable metadata exchange&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;// this is needed for NetCfSvcUtil to discover us&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;ServiceMetadataBehavior smb = new
ServiceMetadataBehavior();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;smb.HttpGetEnabled = true;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:gray;"&gt;serviceHost.Description.Behaviors.Add(smb);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;#endif&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;serviceHost.Open();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Console&lt;/span&gt;.WriteLine(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;quot;CalculatorService is running at &amp;quot;&lt;/span&gt;
+ address.ToString());&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Console&lt;/span&gt;.WriteLine(&lt;span&gt;&amp;quot;Press
&amp;lt;ENTER&amp;gt; to terminate&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Console&lt;/span&gt;.ReadLine();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:green;"&gt;// Close the ServiceHostBase to shutdown the service.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;serviceHost.Close();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;           
}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;catch&lt;/span&gt; (&lt;span&gt;CommunicationException&lt;/span&gt;
ce)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Console&lt;/span&gt;.WriteLine(&lt;span&gt;&amp;quot;An
exception occured: {0}&amp;quot;&lt;/span&gt;, ce.Message);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;serviceHost.Abort();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;The first thing you’ll probably notice is my use of a precompiler
directive.  The reason for this is that we need to run this service once and
then have a tool (that we’ll discuss shortly) connect to it and generate some
code for us.  Once that’s been done we want to remove and change some stuff, but
if you extend this example you’re going to have to go back and have that tool
do its work again, so it’s handy to keep the old code around.  What I did (and
you can see this in the code download) is add another configuration based on
the Debug configuration to the solution called “Discovery” that sets CLIENT_DISCOVERY_BUILD,
so turning this on or off is a simply matter of changing the target
configuration.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;So what does this code do exactly?&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;First it gets the local PC’s IP address (which we then use later on.  Next
it creates an address URI for our service.  You’ll see that I use localhost for
the discovery run.  The reason for this is that the tool (that we’ll discuss
shortly – be patient) actually hard-codes this into some other code.  We’re
going to use string substitution in our client and replacing “localhost” is way
easier than searching through a string for some IP that may change between tool
runs.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Next we create the ServiceHost and add an endpoint.  The important
pieces to note here are that we’re using BasicHttpBinding, which is one of only
2 bindings that the CF version of WCF supports (the other is email through
Exchange ‘07), and that we give a name to the service, which gets used later,
but through generated code.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Next we add the ability to exchange metadata only if we’re in the
Discovery configuration.  The reason for this is that the tool (wait for it!)
can only connect to our service and generate code if this is turned on.  I turn
it off otherwise simply because it seems like a potential security hole if you
leave something like that on in the wild.  Maybe not, but we’ll play it safe
until experience (or someone who knows more about WCF) tells us that we should
do otherwise.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Finally, we open the service and output some stuff on the Console,
waiting for the user to hit Enter to end the app. &lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;That’s all there is to it, so make sure that  CLIENT_DISCOVERY_BUILD is
set and run your app, and you’ll get something exciting like the screen shot
below.  &lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200711/WCF/figure1.PNG"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200711/WCF/figure1.PNG" border="0" alt="" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now let’s do a quick sanity check to make sure it’s actually exposing
itself as a service.  Open a browser on your PC and browse to the address that
the service reported (&lt;a href="http://localhost:8000/calculator"&gt;http://localhost:8000/calculator&lt;/a&gt;). 
You should see something like this:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200711/WCF/figure2.PNG"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200711/WCF/figure2.PNG" border="0" alt="" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Tell everyone around you to stand in awe – you have created the
mythical WCF Service.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;u&gt;The NetCFSvcUtil.exe Tool&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Yes, now we’re going to actually talk about the tool that we talked about. 
The Power Toys for .NET Compact Framework 3.5 ship with a tool called NetCFSvcUtil.exe
which is a lot like its desktop counterpart (that you won’t be using here – believe
me, I tried).  This tool will connect to your service using the metadata
exchange that you enabled in your code and output some code for your CF client
application to use.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now I’m not big on code generators – having seen them evolve for many
years, one thing that has typically been a truism is that they produce
less-than-optimal code, but a quick glance at what this one generates looks reasonable
and besides, we’re here to create a WCF app, not criticize code optimization.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Open a command windows and browse to the folder that contains
NetCFSvcUtil.exe. The default installation of the Power Toys will put it at &lt;i&gt;C:\Program
Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin&lt;/i&gt;.  Next, run the following
command (again, the service must be running when you do this)&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;text-indent:0.5in;line-height:normal;"&gt;&lt;span style="font-size:9pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;netcfSvcUtil.exe
/language:cs http://localhost:8000/calculator&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;You should get an output that looks like this:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;font color="white"&gt;
&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;C:\Program
Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin&amp;gt;netcfSvcUtil.exe /l&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;anguage:cs
http://localhost:8000/calculator&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Microsoft (R)
.NET Compact Framework Service Model Metadata Tool&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;[Microsoft (R)
Windows (R) Communication Foundation, Version 3.5.0.0]&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Copyright (c)
Microsoft Corporation.  All rights reserved.&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Attempting to
download metadata from &amp;#39;http://localhost:8000/calculator&amp;#39; usi&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;ng WS-Metadata
Exchange or DISCO.&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Generating
files...&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;C:\Program
Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin\CalculatorService.cs&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;C:\Program
Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin\CFClientBase.cs&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;C:\Program
Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;background:black none repeat scroll 0% 50%;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;/font&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;And 2 files will be generated in the same folder as NetCFSvcUtil.exe:
CalculatorService.cs and CFClientBase.cs.  You’ll be using these files in the
next step.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;u&gt;The CF Client Application&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now create a Smart Device Windows application named WCFClient and add
the following references (failure to add these references will lead to lots of
colorful language when the code previously generated by NetCFSvcUtil.exe fails
to compile):&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpFirst" style="margin:0in 0in 0.0001pt 0.75in;text-indent:-0.25in;line-height:normal;"&gt;-&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;System.ServiceModel&lt;/p&gt;

&lt;p class="MsoListParagraphCxSpLast" style="margin:0in 0in 0.0001pt 0.75in;text-indent:-0.25in;line-height:normal;"&gt;-&lt;span style="font-family:&amp;#39;Times New Roman&amp;#39;;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;System.Runtime.Serialization&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Next add the two files created by NetCFSvcUtil.exe to the project.  It’s
probably best to copy them to the project folder first to prevent cluttering
the SDK bin directory with all of your generated source.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Next update Form1 to look something like the figure below.  The names
of the controls are on the right and if you want to just copy and paste code,
you’ll need your control names to match these.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200711/WCF/figure3.PNG"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200711/WCF/figure3.PNG" border="0" alt="" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;text-align:center;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;" align="center"&gt;&lt;b&gt;&lt;u&gt;NOTE&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0.5in 0.0001pt;line-height:normal;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;I
was never able to get the emulator to connect to service.  I was able to ping
the emulator from the PC and it was able to browse to a web site, but it wouldn’t
connect to the service.  I then tried it on a real device and it worked, so I
never bothered to go back and try to figure out why the emulator didn’t work. 
I highly suggest that you do run this sample on a real device.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now let’s look at implementing the client.  The first step I did was to
display the device’s local IP address in the Form constructor.  I did this when
I was debugging because the emulator would not connect to the service and I was
wondering if it had a valid IP address.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Update your Form’s constructor code to look like this:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
Form1()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;localIP.Text = &lt;span&gt;Dns&lt;/span&gt;.GetHostEntry(&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;Dns&lt;/span&gt;.GetHostName()).AddressList[0].ToString();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;catch&lt;/span&gt; (&lt;span&gt;Exception&lt;/span&gt;
ex)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;MessageBox&lt;/span&gt;.Show(&lt;span&gt;&amp;quot;No
NIC found?&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now we add all of the service “work” in a Click event handler for the
calculate button.  Add a handler to the button and add the following code to
the handler:&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;
&lt;span style="color:blue;"&gt;void&lt;/span&gt; calculate_Click(&lt;span style="color:blue;"&gt;object&lt;/span&gt;
sender, &lt;span&gt;EventArgs&lt;/span&gt; e)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; a = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;int&lt;/span&gt; b = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;a = &lt;span style="color:blue;"&gt;int&lt;/span&gt;.Parse(first.Text);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;b = &lt;span style="color:blue;"&gt;int&lt;/span&gt;.Parse(second.Text);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;catch&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:green;"&gt;// parsing failed, just bail out&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;   
SMC.&lt;span&gt;Binding&lt;/span&gt; binding = &lt;span&gt;CalculatorClient&lt;/span&gt;.CreateDefaultBinding();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; remoteAddress = &lt;span&gt;CalculatorClient&lt;/span&gt;.EndpointAddress.Uri.ToString();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;remoteAddress = remoteAddress.Replace(&lt;span&gt;&amp;quot;localhost&amp;quot;&lt;/span&gt;,
serviceAddress.Text);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;EndpointAddress&lt;/span&gt; endpoint = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;EndpointAddress&lt;/span&gt;(remoteAddress);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;CalculatorClient&lt;/span&gt; client = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;CalculatorClient&lt;/span&gt;(binding,
endpoint);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;answer.Text = client.Add(a, b).ToString();&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="color:blue;"&gt;catch&lt;/span&gt; (&lt;span&gt;Exception&lt;/span&gt;
ex)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;MessageBox&lt;/span&gt;.Show(ex.Message);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;The important point in this code are that we don’t use the default
constructor for the CalculatorClient, because that would end up using a
remoteAddress with “localhost” in it, because that’s what the code generator
hard-codes it to be.  Instead, we extract that value (it’s a static field of
the generated CalculatorClient) and then use string substitution to replace “localhost”
with the IP address of the PC running the service.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Once we’ve created the CalculatorClient instance, calling the service
is trivially simple.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;u&gt;Conclusion&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;So there you have it - a complete, working, end-to-end example of how
to create a WCF service running on a PC and how to consume it using a Compact
Framework 3.5 application.  As you’ve seen, there isn’t a lot of code to it,
and it’s not overly complex to get set up – it’s just not very well documented
in any one place.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;Now where might you use something like this?  One thing that comes to
mind is the ability to put functionality on a machine somewhere within your
network that can then be called by multiple devices without having to go
through all of the configuration and setup required to get an XML Web Service
under IIS running.  You can then update or fix the service code in one place
and all devices using the function immediately get the benefit without having
to redeploy or roll out the fix.  You could also do computationally-heavy work
on a desktop machine with more power, but still do the collection and display
on a lightweight mobile device.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;At any rate, I hope that this white paper saves someone else a bit of
the headache I went through in trying to get a WCF application running.  Some additional
links that I found at least somewhat useful in researching this are below. 
Enjoy.&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;CF WCF Intro
materials:&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;a href="http://blogs.msdn.com/markprenticems/archive/2007/03/27/introduction-to-windows-communication-foundation-for-the-net-compact-framework-messaging-stack.aspx"&gt;http://blogs.msdn.com/markprenticems/archive/2007/03/27/introduction-to-windows-communication-foundation-for-the-net-compact-framework-messaging-stack.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;The Lunch
Launcher&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoPlainText"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;a href="http://blogs.msdn.com/davidklinems/archive/2007/11/12/the-journey-of-the-lunch-launcher-part-8-what-did-i-learn.aspx"&gt;http://blogs.msdn.com/davidklinems/archive/2007/11/12/the-journey-of-the-lunch-launcher-part-8-what-did-i-learn.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Using
NetCFSvcUtil.exe&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;a href="http://blogs.msdn.com/danhorbatt/archive/2007/09/12/using-compact-svcutil-to-interact-with-servicecontracts.aspx"&gt;http://blogs.msdn.com/danhorbatt/archive/2007/09/12/using-compact-svcutil-to-interact-with-servicecontracts.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Calling WCF
Service from CF 3.5&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;a href="http://blogs.msdn.com/andrewarnottms/archive/2007/09/13/calling-wcf-services-from-netcf-3-5-using-compact-wcf-and-netcfsvcutil-exe.aspx"&gt;http://blogs.msdn.com/andrewarnottms/archive/2007/09/13/calling-wcf-services-from-netcf-3-5-using-compact-wcf-and-netcfsvcutil-exe.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;The CF 3.5
subset of WCF&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;a href="http://blogs.msdn.com/andrewarnottms/archive/2007/08/21/the-wcf-subset-supported-by-netcf.aspx"&gt;http://blogs.msdn.com/andrewarnottms/archive/2007/08/21/the-wcf-subset-supported-by-netcf.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;b&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;Remote
Logging WCF&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:8pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;a href="http://blogs.msdn.com/danhorbatt/archive/2007/11/01/remote-logging-wcf-on-net-compact-framework.aspx"&gt;http://blogs.msdn.com/danhorbatt/archive/2007/11/01/remote-logging-wcf-on-net-compact-framework.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;/div&gt;
&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=58" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author></entry><entry><title>Getting a Millisecond-Resolution DateTime under Windows CE</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/11/20/getting-a-millisecond-resolution-datetime-under-windows-ce.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/11/20/getting-a-millisecond-resolution-datetime-under-windows-ce.aspx</id><published>2007-11-20T18:15:00Z</published><updated>2007-11-20T18:15:00Z</updated><content type="html">&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;November,
2007&lt;br /&gt;Chris Tacke&lt;br /&gt;OpenNETCF
Consulting, LLC&lt;/p&gt;&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" align="middle" border="0" alt="" /&gt;&lt;a href="http://www.opennetcf.com/downloads/download.aspx?s=msClock" class="" title="Download the Source" target="_blank"&gt;&lt;font color="#0066cc"&gt;Download the Source Code&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;font color="#0066cc"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" height="30" alt="" /&gt;&amp;nbsp;&lt;/font&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200711/msClock/ms-Resolution%20DateTime.pdf" class="" title="Download the PDF" target="_blank"&gt;&lt;font color="#0066cc"&gt;Download the PDF&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:18pt;line-height:115%;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Introduction&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;



&lt;p class="MsoNormal"&gt;One seemingly strange behavior that Windows CE devices (including
Pocket PC, Smartphone and Windows Mobile devices) exhibit is that when you
query the device time, you get back either a zero of some constant but invalid
value for the milliseconds field.  This is true whether you call GetLocalTime
or GetSystemTime in native code or DateTime.Now in managed code.  Why is it
that devices running an OS that has real-time capabilities can’t provide us as
developers with a clock that has simple millisecond resolution?  The answer
lies not in the OS – which is quite capable of giving that resolution – but in
how the time function is implemented by the device OEM.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Typically Windows CE devices contain a piece of hardware
internally called a real time clock or RTC.  The RTC is very accurate, but
often has a resolution of only 1 second.  When the OS was implemented, most
OEMs simply return the value that the RTC holds and therefore when you query
the time that’s all you get.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;So the question remains – how can we as developers get a
millisecond-resolution time?  If you’re simply looking to get the time short
tasks take, then often calling GetTickCount or Environment.TickCount (which is
the number of milliseconds since the OS started and tied to a separate
oscillator in the processor) is sufficient, but what if we want a true time
stamp with a millisecond field?  The answer is that we simply have to calculate
it.  In this white paper we’ll look at code that does that calculation and to make
our code reusable, we’ll create a simple class called DateTime2 that will
expose a Now property that has millisecond resolution.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;u&gt;Calculating the millisecond field&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Since we know that the Environment.TickCount returns the
number of milliseconds since startup, we know that we have access to data that
can become our millisecond field.  By using modulo division on it we can get a “current
millisecond” piece of data:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-left:0.5in;"&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;int&lt;/span&gt;&lt;span style="font-size:10pt;line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;"&gt; tick = &lt;span&gt;Environment&lt;/span&gt;.TickCount % 1000;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-left:0.5in;"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;However the problem with this is that there’s only a 1 in
1000 chance that it will be  synchronized with the system clock, so it’s more
than likely that this millisecond tick will roll over to zero at a time when
the system clock is not rolling over.  All we have to do then is manually synchronize
that rollover.  To do that we simply need to find what the value of the above
tick is when the clock rolls its second value over.  So during initialization
of our class, we simply poll the clock repeatedly and quickly until we see the
second roll over, then we calculate the offset.  Bear in mind that this initialization
can take up to 1 second to complete.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt;
&lt;span style="color:blue;"&gt;int&lt;/span&gt; m_offset = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; DateTime2()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;int&lt;/span&gt;
s = &lt;span&gt;DateTime&lt;/span&gt;.Now.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;while&lt;/span&gt;
(&lt;span style="color:blue;"&gt;true&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; s2 = &lt;span&gt;DateTime&lt;/span&gt;.Now.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wait
for a rollover&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (s != s2)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            m_offset = &lt;span&gt;Environment&lt;/span&gt;.TickCount % 1000;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So now that we have our offset, we simply use it to
calculate our millisecond field every time the Now property is retrieved.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt;
&lt;span&gt;DateTime&lt;/span&gt; Now&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;get&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:green;"&gt;// find where we are based on the os tick&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; tick = &lt;span&gt;Environment&lt;/span&gt;.TickCount
% 1000;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:green;"&gt;// calculate our ms shift from our base m_offset&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; ms = (tick &amp;gt;= m_offset) ? (tick - m_offset) :
(1000 - (m_offset - tick));&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:green;"&gt;// build a new DateTime with our calculated ms&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:green;"&gt;// we use a new DateTime because some devices fill ms with
a non-zero garbage value&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span&gt;DateTime&lt;/span&gt; now = &lt;span&gt;DateTime&lt;/span&gt;.Now;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;DateTime&lt;/span&gt;(now.Year, now.Month, now.Day, now.Hour,
now.Month, now.Second, ms);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;u&gt;Testing our code&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So now that we have a function that is logically sound, how
do we check that it really works?  First, toss out any idea that you might test
or use this on the emulator.  The emulator emulates hardware, including the RTC
and the system tick and is therefore completely unreliable for any type of time
testing (I actually tested in with this code and saw major creep of the millisecond
field across the second rollover period).&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;To test the function on actual hardware, we use logic that
is pretty much the same as our offset initialization code.  We simply want to
watch the system clock roll over, and when it does, we want to get the
millisecond field of our DateTime.  It should be at or near zero, and more importantly
it should be consistent. So let’s look at what a test function might look like.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt;
Test()&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;int&lt;/span&gt;
seconds = 5;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;int&lt;/span&gt;
s = &lt;span&gt;DateTime2&lt;/span&gt;.Now.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;while&lt;/span&gt;
(seconds &amp;gt; 0)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span&gt;DateTime&lt;/span&gt; dt = &lt;span&gt;DateTime2&lt;/span&gt;.Now;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; s2 = dt.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (s != s2)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           
System.Diagnostics.&lt;span&gt;Debug&lt;/span&gt;.WriteLine(&lt;span&gt;&amp;quot;Test ms=&amp;quot;&lt;/span&gt; + dt.Millisecond);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            s = dt.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            seconds--;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin-bottom:0.0001pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;When I ran this on a Dell Axim x51 I found that the tick
repeatedly came out around 998 or so, meaning that my millisecond field would
actually roll to zero a couple milliseconds before the actual second field.  For
many applications this might be fine, but of course we can do better, right? 
If we can test the inaccuracy, we can always account for it.  So let’s add a
Calibrate function to our DateTime2 class that will run our test code logic for
a period of time, calculate the average offset from zero over that period and
then adjust our global offset by that average.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt;
&lt;span style="color:blue;"&gt;void&lt;/span&gt; Calibrate(&lt;span style="color:blue;"&gt;int&lt;/span&gt;
seconds)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;int&lt;/span&gt;
s = &lt;span&gt;DateTime2&lt;/span&gt;.Now.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;int&lt;/span&gt;
sum = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;int&lt;/span&gt;
remaining = seconds;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;while&lt;/span&gt;
(remaining &amp;gt; 0)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span&gt;DateTime&lt;/span&gt; dt = &lt;span&gt;DateTime2&lt;/span&gt;.Now;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;int&lt;/span&gt; s2 = dt.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (s != s2)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;           
System.Diagnostics.&lt;span&gt;Debug&lt;/span&gt;.WriteLine(&lt;span&gt;&amp;quot;ms=&amp;quot;&lt;/span&gt; + dt.Millisecond);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            remaining--;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span style="color:green;"&gt;// store the offset from zero&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            sum +=
(dt.Millisecond &amp;gt; 500) ? (dt.Millisecond - 1000) : dt.Millisecond;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            s = dt.Second;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:green;"&gt;//
adjust the offset by the average deviation from zero (round to the integer
farthest from zero)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;if&lt;/span&gt;
(sum &amp;lt; 0)&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        m_offset += (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)&lt;span&gt;Math&lt;/span&gt;.Floor(sum
/ (&lt;span style="color:blue;"&gt;float&lt;/span&gt;)seconds);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    &lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    {&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        m_offset += (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)&lt;span&gt;Math&lt;/span&gt;.Ceiling(sum
/ (&lt;span style="color:blue;"&gt;float&lt;/span&gt;)seconds);&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;    }&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal" style="margin:0in 0in 0.0001pt 0.5in;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;After I ran Calibrate for 5 seconds on the same device, I
found that Test spit out an offset of zero very repeatedly, which is what we want.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;u&gt;Conclusion&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So we now understand that most CE devices don’t fill the
milliseconds field of their system time because it’s not readily available, and
we’ve seen that with a little extra code we can derive a reasonably accurate
replacement that does.  Our new DateTime2 class provides a reasonable utility
class that can be used in a lot of applications where you’d like to have a
millisecond field.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Keep in mind, however, that what we have here is still based
on two separate oscillators on the device and those two will drift apart over
time.  Your offset might be zero today, but if you run the app for a week I
would expect you’ll find it to have drifted a few ticks - how much depends on
the hardware, its layout and the temperature the device is at. Also keep in
mind that managed code is still nondeterministic.  Just because you get a millisecond
accurate time doesn’t mean that you can reliably do tasks with millisecond
accuracy.&lt;/p&gt;
&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=51" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Workarounds" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Workarounds/default.aspx" /></entry><entry><title>Using GDI+ on Windows Mobile</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/10/31/using-gdi-on-windows-mobile.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/10/31/using-gdi-on-windows-mobile.aspx</id><published>2007-10-31T16:39:00Z</published><updated>2007-10-31T16:39:00Z</updated><content type="html">&lt;p class="MsoNormal"&gt;&lt;span&gt;Alex Feinman&lt;br /&gt;OpenNETCF Consulting&lt;br /&gt;October 2007&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" align="middle" border="0" alt="" /&gt;&lt;a class="" title="Download the Source" href="http://www.opennetcf.com/downloads/download.aspx?s=GDIPlusCF" target="_blank"&gt;&lt;font color="#0066cc"&gt;Download the Source Code&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;font color="#0066cc"&gt;&lt;img height="30" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;&amp;nbsp;&lt;/font&gt;&lt;a class="" title="Download the PDF" href="http://community.opennetcf.com/blogs/cf/200710/GDIPlus/Using%20GDI+%20on%20Windows%20Mobile.pdf" target="_blank"&gt;&lt;font color="#0066cc"&gt;Download the PDF&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h1 class="Section1"&gt;&lt;span&gt;What is GDI+&lt;/span&gt;&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;GDI+ is a library created to add rich drawing and imaging feature to the basic set of Windows APIs. It has been introduced in Windows 2000 timeframe and eventually became a basis of System.Drawing and System.Drawing.Imaging namespaces. GDI+ is a dual API. It has a set of rich objects, such as Graphics, Bitmap, Pen, Brush etc as well, as a flat API suitable for use in legacy C or for P/Invoking. Starting with Windows Mobile 5 (Pocket PC), GDI+ ships on Windows Mobile devices. Despite the fact that the desktop .NET drawing and imaging support is built on top of GDI+, the Compact Framework does not use it. This in part explains somewhat more Spartan selection of graphic features available in Compact framework. Of course one of the main reasons for this was the lack of universal availability of GDI+. E.g it is not present on 2003 and 2003 SE devices, any version of smartphone (including Windows Mobile&amp;nbsp; 6 Standard) or basic Windows CE. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;It is also important to understand that Windows Mobile version of GDI+ lacks many features of its desktop counterpart. Although it is 100% API-compatible, a lot of calls is simply not implemented. All it does is returning the corresponding status (NotImplemented) to the caller. &lt;/span&gt;&lt;/p&gt;
&lt;h1 class="Section1"&gt;&lt;span&gt;Why GDI+&lt;/span&gt;&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;As I understand it, the need for GDI+ has been driven by inking support. Transcriber (an Input Method supporting cursive recognition) and in WinMo 6 WISPLite (inking and recognition support) both use GDI+ internally. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;GDI+ allows drawing with antialiasing, transparency and some limited 2D transformation support. Currently, there is no other way to draw an antialiased polyline, curve or other object in Windows CE, than by using GDI+.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;GDI+ supports Rectangles, Pies, Ellipses, Beziers as part of a Path object. It also supports various special types of pens and brushes including gradients. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Things notably missing from Windows Mobile version of GDI+ are:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Text support&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;World Transform support. In general transforms are only supported on a Path object&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;Many image operations&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;From the performance standpoint GDI+ is a slow-ish API. It needs to be used judiciously and sparingly. Caching complex objects as bitmaps also helps.&lt;/span&gt;&lt;/p&gt;
&lt;h1 class="Section1"&gt;&lt;span&gt;How&lt;/span&gt;&lt;/h1&gt;
&lt;h2 class="Section1"&gt;&lt;span&gt;API access&lt;/span&gt;&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;GDI+ API consists of 2 parts. One is GDIPLUS.DLL, which exports so-called flat API – a large number of C functions that comprise the entire functional set of the API. The other is a set of C++ objects, found in the include directory of Platform SDK, which encapsulates flat API functionality, provides memory management, cleanup and some useful shortcuts. When using GDI+ from Compact Framework, it is relatively easy to P/Invoke the flat API. The class-based API is a different thing. It is absolutely, 100% incompatible with Compact Framework. It can however be recreated in C# and given its usefulness, it should be.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Caution needs to be exercised, when using GDI+. The code needs to make sure that the platform indeed has GDIPLUS.DLL and be prepared to deal with the lack of it, for example by falling back to less rich, traditional methods of drawing.&lt;/span&gt;&lt;/p&gt;
&lt;h2 class="Section1"&gt;&lt;span&gt;Session initialization and termination&lt;/span&gt;&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Before GDI+ can be used, a call to “GdiplusStartup” needs to be made:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;GdiplusStartupInput&lt;/span&gt; input = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GdiplusStartupInput&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;GdiplusStartupOutput&lt;/span&gt; output;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;GpStatus&lt;/span&gt; stat = &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.GdiplusStartup(&lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; token, input, &lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; output);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;The above code initializes GDI+ subsystem. The parameters can be ignored – there is not much use to them unless you have a debug build of GDIPLUS.DLL, which is not likely. This is also a good place to add try/catch and watch for MissingMethodException. Getting one would typically indicate that your platform does not have GDIPLUS.DLL available.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;When the application is shutting down (or GDI+ is not needed anymore), the following call is required:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.GdiplusShutdown(token);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Following this call no other GDI+ calls are allowed.&lt;/span&gt;&lt;/p&gt;
&lt;h2 class="Section1"&gt;&lt;span&gt;Managed wrapper&lt;/span&gt;&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;To be able to use GDI+ in a Compact Framework application, we need to wrap most of the flat API and port the object model. This is done for you in OpenNETCF.GDIPlus.dll assembly. It has a class called NativeMethods, where all of the flat API is exposed. It also has objects matching GDI+ objects. Among those are:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;GraphicsPlus&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;ImagePlus&lt;/span&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;BitmapPlus&lt;/span&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;GraphicsPath&lt;/span&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;BrushPlus and its derivative classes:&lt;/span&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;span&gt;SolidBrushPlus&lt;/span&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;span&gt;HatchBrush&lt;/span&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;span&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;span&gt;PathGradientBrush&lt;/span&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&lt;span&gt;TextureBrushPlus&lt;/span&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;PenPlus&lt;/span&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;&lt;/span&gt;&lt;span&gt;RegionPlus&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;h2 class="Section1"&gt;&lt;span&gt;Drawing with GDI+&lt;/span&gt;&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;All drawing in GDI+ is done using GraphicsPlus object, similar to how in .NET all drawing is done using Graphics object. In order to obtain GraphicsPlus object an appropriate constructor needs to be used. For example to draw inside OnPaint override (or wherever .NET Graphics object is available), one would use a constructor that takes HDC:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;protected&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; OnPaint(&lt;span style="COLOR:#2b91af;"&gt;PaintEventArgs&lt;/span&gt; e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IntPtr&lt;/span&gt; hdc = e.Graphics.GetHdc();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;using&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;GraphicsPlus&lt;/span&gt; g = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GraphicsPlus&lt;/span&gt;(hdc))&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PaintControl(g);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Graphics.ReleaseHdc(hdc);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;If the drawing target is an off-screen bitmap, then there is a choice of creating a .NET Graphics object on it followed by the above, or using Bitmap.GetHbitmap() and then constructing GraphicsPlus object on HBITMAP. There are some other choices, but mostly of limited use.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;While its desktop peer supports many settings, the Windows Mobile version of Graphics object supports only one – smoothing mode. It can be sent to None, Antialias, High Speed and High Quality. Naturally, antialised output takes the longest time to render.&lt;/span&gt;&lt;/p&gt;
&lt;h3 class="Section1"&gt;&lt;span&gt;Brushes&lt;/span&gt;&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Brush objects in GDI+ can be used to draw directly on the screen by filling various shapes as well as to create pens that use brush textures to fill the line. Below are several brush examples:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img title="BrushDemo.png" style="WIDTH:240px;HEIGHT:320px;" height="320" alt="BrushDemo.png" src="http://community.opennetcf.com/blogs/cf/200710/GDIPlus/BrushDemo.png" width="240" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;In order to create the above brushes the following code was used:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;PathGradient brush&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;// Create rectangular path&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;GraphicsPath&lt;/span&gt; path = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GraphicsPath&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;FillMode&lt;/span&gt;.FillModeAlternate);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path.AddRectangle(&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GpRectF&lt;/span&gt;( 0, 0, ClientRectangle.Width,&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ClientRectangle.Height / 5));&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;// Create rectangular gradient brush&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;// with red in center and black in the corners&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brPathGrad = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PathGradientBrush&lt;/span&gt;(path);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brPathGrad.SetCenterColor(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Red);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; count = 2;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brPathGrad.SetSurroundColors(&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;[] { &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black },&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;ref&lt;/span&gt; count);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&lt;/span&gt;&lt;span&gt;Solid Brush&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brSolid = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;SolidBrushPlus&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.CornflowerBlue);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-SIZE:7pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;Hatch Brush&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brHatch = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;HatchBrush&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;HatchStyle&lt;/span&gt;.HatchStyle25Percent,&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.White);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;Linear Gradient&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brLinGrad = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;LinearGradientBrush&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GpPointF&lt;/span&gt;(0, 0),&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GpPointF&lt;/span&gt;(50, 50), &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.White);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;Texture brush&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;StreamOnFile&lt;/span&gt; sf = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;StreamOnFile&lt;/span&gt;(bitmapPath);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;ImagePlus&lt;/span&gt; img = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;ImagePlus&lt;/span&gt;(sf, &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brTexture = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;TextureBrushPlus&lt;/span&gt;(img, &lt;span style="COLOR:#2b91af;"&gt;WrapMode&lt;/span&gt;.WrapModeTile);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 class="Section1"&gt;&lt;span&gt;Pens&lt;/span&gt;&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Pens in GDI+ support thickness, transparency, antialiasing, custom caps, and some other features. In addition a pen can be created solid, hatched and generally based on any brush one can create. Using pens it is possible to draw lines, rectangles, ellipses, beziers and otherwise random paths. &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Pens support start and end caps. Caps can be predefined or entirely custom, based on a path object.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Below is a sample of the output from various pens used under various conditions:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img title="PenDemo.png" style="WIDTH:240px;HEIGHT:320px;" height="320" alt="PenDemo.png" src="http://community.opennetcf.com/blogs/cf/200710/GDIPlus/PenDemo.png" width="240" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;Here is how each pen has been created and used:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:7pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;Solid with caps. Standard caps are used – round and arrow&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brSolid = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;SolidBrushPlus&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.CornflowerBlue);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolid = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PenPlus&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Red, 10);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolid.SetEndCap(&lt;span style="COLOR:#2b91af;"&gt;LineCap&lt;/span&gt;.LineCapRound);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolid.SetStartCap(&lt;span style="COLOR:#2b91af;"&gt;LineCap&lt;/span&gt;.LineCapArrowAnchor);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:7pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;Solid with caps and antialiasing. This one is the same as before except it is drawn with antialiasing&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.SetSmoothingMode(&lt;span style="COLOR:#2b91af;"&gt;SmoothingMode&lt;/span&gt;.SmoothingModeAntiAlias);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolid.SetColor(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Blue);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;Hatched (25%)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brHatch = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;HatchBrush&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;HatchStyle&lt;/span&gt;.HatchStyle25Percent,&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.White);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penHatch = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PenPlus&lt;/span&gt;(brHatch, 10);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;Solid with transparency&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolidTrans = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PenPlus&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.FromArgb(-0x5f7f7f7f), 10);&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Custom cap. The custom cap has been created out of a path object consisting of a single ellipse&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolidCustomCap = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PenPlus&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, 20);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;GraphicsPath&lt;/span&gt; path = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GraphicsPath&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;FillMode&lt;/span&gt;.FillModeAlternate);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path.AddEllipse(-0.5f, -1.5f, 1, 3);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;CustomLineCap&lt;/span&gt; cap = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;CustomLineCap&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;,path, &lt;span style="COLOR:#2b91af;"&gt;LineCap&lt;/span&gt;.LineCapFlat, 0);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penSolidCustomCap.SetCustomEndCap(cap);&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span&gt;Dash&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penDash = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PenPlus&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, 5);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penDash.SetDashStyle(&lt;span style="COLOR:#2b91af;"&gt;DashStyle&lt;/span&gt;.DashStyleDot);&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&lt;/span&gt;&lt;span&gt;Gradient brush-based&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brGrad = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;LinearGradientBrush&lt;/span&gt;(&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GpPointF&lt;/span&gt;(0, 0), &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;GpPointF&lt;/span&gt;(100, 100),&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Black, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.White);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; penGradient = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PenPlus&lt;/span&gt;(brGrad, 30);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;span style="FONT-SIZE:11pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;
&lt;div class="Section1"&gt;&lt;br style="PAGE-BREAK-BEFORE:always;" /&gt;&lt;/div&gt;&lt;/span&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="COLOR:#4f81bd;FONT-FAMILY:&amp;#39;Cambria&amp;#39;,&amp;#39;serif&amp;#39;;"&gt;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1 class="Section1"&gt;&lt;span&gt;Demo application&lt;/span&gt;&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;This whitepaper includes a demo application. The application demonstrates the above techniques as well as shows how to use GDI+ to capture ink with smoothing and antialiasing.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img title="Main.png" style="WIDTH:240px;HEIGHT:320px;" height="320" alt="Main.png" src="http://community.opennetcf.com/blogs/cf/200710/GDIPlus/Main.png" width="240" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1 class="Section1"&gt;&lt;span&gt;Conclusion&lt;/span&gt;&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;&lt;span&gt;GDI+ is available on modern Windows Mobile platform that support stylus input. It allows creating graphic applications that are hard or impossible to implement otherwise. Using GDI+ in conjunction with Compact .NET Framework allows a developer to create a rich graphic application without expending substantial effort.&lt;/span&gt;&lt;/p&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=44" width="1" height="1"&gt;</content><author><name>marteaga</name><uri>http://community.opennetcf.com/members/marteaga.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Graphics" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Graphics/default.aspx" /></entry><entry><title>Sharing Windows Mobile Ink with the Desktop</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/09/28/sharing-windows-mobile-ink-with-the-desktop.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/09/28/sharing-windows-mobile-ink-with-the-desktop.aspx</id><published>2007-09-28T19:42:00Z</published><updated>2007-09-28T19:42:00Z</updated><content type="html">




&lt;div class="Section1"&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;Mark Arteaga &lt;br /&gt;OpenNETCF Consulting&lt;/p&gt;
&lt;p class="MsoNormal"&gt;September 2007&lt;/p&gt;
&lt;p class="MsoToc1"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" align="middle" border="0" alt="" /&gt;&lt;a class="" title="Download the Source" href="http://www.opennetcf.com/downloads/download.aspx?s=OpenNETCFMobileInkLibrary-1.0" target="_blank"&gt;&lt;font color="#0066cc"&gt;Download the Source Code&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;font color="#0066cc"&gt;&lt;img height="30" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;&amp;nbsp;&lt;/font&gt;&lt;a class="" title="Download the PDF" href="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop.pdf" target="_blank"&gt;&lt;font color="#0066cc"&gt;Download the PDF&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p class="MsoToc1"&gt;Contents&lt;/p&gt;
&lt;p class="MsoToc2"&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178752131"&gt;Introducation&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178752132"&gt;Ink Serialized Format Data&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178752133"&gt;Sharing Ink With A Custom Application&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178752134"&gt;Sharing Ink with One Note 2007&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178752135"&gt;What’s Next&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178752136"&gt;Conclusion&lt;/a&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178752131" name="_Toc178752131"&gt;&lt;/a&gt;Introducation&lt;/h2&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;In the &lt;a href="http://community.opennetcf.com/articles/cf/archive/2007/09/28/using-the-opennetcf-mobile-ink-library-for-windows-mobile-6.aspx"&gt;previous article&lt;/a&gt; we discussed technical information on the Mobile Ink Library and WISP Lite.&amp;nbsp; In this article we will discuss how the Ink Serialized Format (ISF) data can be shared on both a Windows Mobile 6 application and an application running on the desktop.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178752132" name="_Toc178752132"&gt;&lt;/a&gt;&lt;a class="" title="_Toc178569079" name="_Toc178569079"&gt;&lt;/a&gt;Ink Serialized Format Data&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;Ink Serialized Format (or ISF) is the binary format in which the ink data is persisted as.&amp;nbsp; This format directly compatible to the Tablet PC ink format and can be interchanged on both the Table PC and a Windows Mobile 6 device.&amp;nbsp; Using ISF data that was saved on a Tablet PC on a Windows Mobile device, Windows Mobile will ignore any properties in the ISF stream that are not supported but still preserve the properties when saved again.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal"&gt;As developer using the Mobile Ink Library you have the option to persist the ink data as either as:&lt;/p&gt;
&lt;ol&gt;
&lt;li class="MsoNormal" style="LINE-HEIGHT:normal;"&gt;Ink Serialized Format - The ink data using ISF.&amp;nbsp; This is the most compact representation of ink data. &lt;/li&gt;
&lt;li class="MsoNormal" style="LINE-HEIGHT:normal;"&gt;Base64 Ink Serialized Format - The ink data using ISF and Base64 encoded. &lt;/li&gt;
&lt;li class="MsoNormal" style="LINE-HEIGHT:normal;"&gt;Gif - The ink data in Graphics Interchange Format (Gif) &lt;/li&gt;
&lt;li class="MsoNormal" style="LINE-HEIGHT:normal;"&gt;Base64 Gif - The ink data Graphics Interchange Format (Gif) and Base64 encoded&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;In the next sections we’ll look at sharing ISF data in a custom desktop application and a Windows Mobile application and also importing ISF data created on a Windows Mobile device into One Note 2007. &lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178752133" name="_Toc178752133"&gt;&lt;/a&gt;Sharing Ink With A Custom Application&lt;/h2&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Since ISF data produced on the desktop is binary compatible on a Windows Mobile 6 Device and vice-versa I decided to take the common scenario of signature capture on a mobile device and display the data on a custom application written using the .NET Framework running on the desktop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The Mobile Ink Library includes a sample called InkSerializationCF which captures a users signature and embeds an ExtendedProperty within the ISF stream.&amp;nbsp; We will use this sample to show how the ISF data can be shared with the desktop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Note, if you want the try this sample on the desktop you will need to install a few SDKs.&amp;nbsp; Here is a chart summarizing what is need on different operating systems.&lt;/span&gt;&lt;/p&gt;
&lt;table class="MsoTableGrid" style="BORDER-RIGHT:medium none;BORDER-TOP:medium none;BORDER-LEFT:medium none;BORDER-BOTTOM:medium none;BORDER-COLLAPSE:collapse;" cellspacing="0" cellpadding="0" class="MsoTableGrid"&gt;

&lt;tr&gt;
&lt;td class="" style="BORDER-RIGHT:black 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:black 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:black 1pt solid;WIDTH:239.4pt;PADDING-TOP:0cm;BORDER-BOTTOM:black 1pt solid;"&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Operating System&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="BORDER-RIGHT:black 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:black 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:medium none;WIDTH:239.4pt;PADDING-TOP:0cm;BORDER-BOTTOM:black 1pt solid;"&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;SDK Requirements&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" style="BORDER-RIGHT:black 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:medium none;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:black 1pt solid;WIDTH:239.4pt;PADDING-TOP:0cm;BORDER-BOTTOM:black 1pt solid;"&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Windows Vista&lt;br /&gt;Windows XP Tablet PC 2005&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="BORDER-RIGHT:black 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:medium none;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:medium none;WIDTH:239.4pt;PADDING-TOP:0cm;BORDER-BOTTOM:black 1pt solid;"&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=117ECFD3-98AD-4D67-87D2-E95A8407FA86&amp;amp;displaylang=en"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Windows Vista SDK&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" style="BORDER-RIGHT:black 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:medium none;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:black 1pt solid;WIDTH:239.4pt;PADDING-TOP:0cm;BORDER-BOTTOM:black 1pt solid;"&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Windows XP&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="BORDER-RIGHT:black 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:medium none;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:medium none;WIDTH:239.4pt;PADDING-TOP:0cm;BORDER-BOTTOM:black 1pt solid;"&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=69640b5c-0ee9-421e-8d5c-d40debee36c2&amp;amp;displaylang=en"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Windows XP Tablet PC SDK&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=117ECFD3-98AD-4D67-87D2-E95A8407FA86&amp;amp;displaylang=en"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Windows Vista SDK&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Changes Since First Release&lt;/h3&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Since the Mobile Ink Library was first released, I have gone ahead and made some changes to align the classes more with the Microsoft.Ink classes available.&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The first change was to the OpenNETCF.WindowsMobile.Ink.InkOverlay class.&amp;nbsp; This class has been renamed to OpenNETCF.WindowsMobile.Ink.Ink class.&amp;nbsp; The InkOverlay class has been marked obsolete and is still available.&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 1" style="WIDTH:427px;HEIGHT:290px;" height="290" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image001.jpg" width="427" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;In the above diagram you will notice in the OpenNETCF.WindowsMobile.Ink.Ink class we also added a new property called ExtendedProperties.&amp;nbsp; These are the custom properties you can add to an ISF stream.&amp;nbsp; In the case of the signature sample application we add the date the signature was saved, the first name and last name of the person signing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Next is the InkControlBase class.&amp;nbsp; We have added a new property called Ink which exposes the Ink object discussed above.&amp;nbsp; Since we are using the OpenNETCF.WindowsMobile.Ink.InkPicture control as a base class for the OpenNETCF.WindowsMobile.Ink.InkSignature control and since InkPicture inherits from InkControlBase, this will help us keep the same object model as the Microsoft.Ink.InkPicture control.&amp;nbsp; Here is a class diagram of the controls in the Mobile Ink Library:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img style="WIDTH:499px;HEIGHT:634px;" height="634" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image002.jpg" width="499" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Having a similar object model allows us to use the same InkSignature control on both the Windows Mobile application and the Desktop application.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;Sharing the InkSignature Control&lt;/h3&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Now that some appropriate changes have been made to the Mobile Ink Library classes to align with the Microsoft.Ink classes, we can now look at how we can share ISF data generated from a Windows Mobile 6 device within a desktop application.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The InkSignature control is a custom control that will capture signature data.&amp;nbsp; It derives from InkPicture and since we change the classes to align more with the desktop we just have to change the internal implementation of InkSignature to be able to share the control on both the desktop and the device.&amp;nbsp; (For more information on sharing code between .NET Compact Framework and .NET Framework see this &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/07/ShareCode/"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;article&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; in &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/msdnmag"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;MSDN Magazine&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;.)&amp;nbsp; By using conditional compile statements we are able to have code in the same source file for both the device and the desktop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;To implement the code sharing we will be working with two separate solutions.&amp;nbsp; The first is InkSerializationCF which is a .NET Compact Framework project for Windows Mobile 6 device.&amp;nbsp; The second is InkSerializationFx which is the .NET Framework application that runs on the desktop.&amp;nbsp; The InkSerializationFx application will only be used to view any signatures saved via the InkSerializationCF application.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The main change to accomplish the code sharing is to the InSignature.Open(string) method.&amp;nbsp; Here we have used conditional compiles to allow us to use on both the desktop and device.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#if&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; !Fx&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; Open(&lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; file)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#else&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public void Open(string file)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#endif&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#if&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; !Fx&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.Open(file);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#else&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.InkEnabled = false;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StreamReader sr = new StreamReader(file);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] data = Encoding.ASCII.GetBytes(sr.ReadToEnd());&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sr.Close();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Ink = new Microsoft.Ink.Ink();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Ink.Load(data);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Refresh();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#endif&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//See if the ISF file opened is valid&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;object&lt;/span&gt; ret = &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.Ink.ExtendedProperties[&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Guid&lt;/span&gt;(m_sigValidationGuid)].Data;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (ret == &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#if&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; !Fx&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.Clear();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#else&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.InkEnabled = false;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Ink = new Microsoft.Ink.Ink();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.InkEnabled = true;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#endif&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_firstname = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_lastname = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_dateSigned = &lt;span style="COLOR:#2b91af;"&gt;DateTime&lt;/span&gt;.MinValue;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;throw&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Exception&lt;/span&gt;(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Invalid signature file!&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Retreive the firstname extended properties&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.Ink.ExtendedProperties[&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Guid&lt;/span&gt;(m_firstNameGuid)].Data;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_firstname = ret.ToString();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Retreive the lastName extended properties&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.Ink.ExtendedProperties[&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Guid&lt;/span&gt;(m_lastNameGuid)].Data;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_lastname = ret.ToString();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Retreive the date the sign was signed&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.Ink.ExtendedProperties[&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Guid&lt;/span&gt;(m_dateSignedGuid)].Data;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_dateSigned = &lt;span style="COLOR:#2b91af;"&gt;DateTime&lt;/span&gt;.FromFileTime(&lt;span style="COLOR:blue;"&gt;long&lt;/span&gt;.Parse(ret.ToString()));&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The Open() method will extract the signature information, and all the ExtendedProperties that contains the date signed, and first and last name.&amp;nbsp; From the above code you will notice not many changes are needed to be able to use the same source file on the desktop and on the device.&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;In the InkSerializationFx project, we need to add a reference to Microsoft.Ink (since OpenNETCF.WindowsMobile.Ink is not supported on the desktop).&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 4" style="WIDTH:276px;HEIGHT:395px;" height="395" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image003.jpg" width="276" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Then we also have to add a using statement with a conditional compile so InkSerializationCF does not use it:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#if&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; Fx&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; Microsoft.Ink;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.IO;&lt;br /&gt;&lt;span style="COLOR:blue;"&gt;#endif&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;A conditional compile statement was also added to the Save() method since the InkSerializationFx does not allow any modification of the signature data.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#if&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; !Fx&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public void Save(string filename, string firstName, string lastName, InkPersistenceFormat format)&lt;br /&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;#endif&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The InkSerializationCF sample was also modified to save the ISF data in different formats.&amp;nbsp; One thing to note is when sharing the ISF data with the desktop, you can only use the ISFBase64 format as the regular ISF stream will not load.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;After all this talk about code let’s see the results.&amp;nbsp; Here are the results of a signature on a Windows Mobile 6 device.&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 7" style="WIDTH:480px;HEIGHT:640px;" height="640" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image004.jpg" width="480" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;And the results on the desktop.&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 10" style="WIDTH:300px;HEIGHT:300px;" height="300" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image005.jpg" width="300" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;For the desktop signature application, the signature is read-only as on the desktop you don’t want the signature to be modified.&amp;nbsp; You can add more ink to the ISF file and if you try to load it on the device, you will see those changes.&amp;nbsp; I will leave it up to the reader to explore that scenario.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Now that you have knowledge on sharing ink data between a desktop application and a Windows Mobile device, next we will look at sharing the ISF data with One Note 2007.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178752134" name="_Toc178752134"&gt;&lt;/a&gt;Sharing Ink with One Note 2007&lt;/h2&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Since ISF data is compatible on the desktop and a Windows Mobile 6 device,&amp;nbsp; I decided to explore one of the comments in the ‘Readme.txt’ file in the Windows Mobile 6 SDK which said:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Lucida Console&amp;#39;;"&gt;“These ink notes can also be imported to OneNote on the desktop.”&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;Well, not being a regular user of One Note but seeing the value this can possibly have in an application I decided to explore this comment a bit.&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;Integration with OneNote&lt;/h3&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;When InkNotesCF was first ported from the native sample it allowed the user to save the note in a certain Xml format as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;xml&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;version&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;1.0&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Import&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;xmlns&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;http://schemas.microsoft.com/office/onenote/2004/import&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;EnsurePage&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;path&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;Pocket Notes\InkFiles.one&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;guid&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;3855d272-28de-4a3f-b157-4eca51c5d15a&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;title&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;\Storage Card\note2003.ink&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;PlaceObjects&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;pagePath&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;Pocket Notes\InkFiles.one&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;pageGuid&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;476d389f-a48b-4891-b665-148a6ed7d9d1&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Object&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;guid&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&amp;quot;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Position&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;x&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;y&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Ink&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Data&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Data&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Ink&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Object&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;PlaceObjects&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Import&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;As you can see from the Xml namespace the version of OneNote that was used when the native sample was created was OneNote 2003.&amp;nbsp; This Xml format was also ported to the managed InkNoteCF sample.&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;With the release of OneNote 2007, the COM API has changed which also resulted in a new Xml schema to import ink data into OneNote.&amp;nbsp; We will not go through the changes but for more information on OneNote 2007 from a developers perspective see ‘&lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms788684.aspx"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;What’s New for Developers in OneNote 2007 (Part 1)&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;’ and ‘&lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa286798.aspx"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;What’s New for Develoeprs in OneNote 2007 (Part 2)&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;’&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The new Xml structure for importing data into one is as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Page&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;xmlns:one&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;http://schemas.microsoft.com/office/onenote/2007/onenote&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;ID&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;{0}&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Title&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:OE&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:red;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;author&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;=&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;Mark Arteaga&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;lastModifiedBy&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;Mark Arteaga&lt;/span&gt;&amp;quot;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:T&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&amp;lt;![CDATA[&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;\Storage Card\note2003.ink&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;]]&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:T&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:OE&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Title&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Outline&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:OEChildren&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:OE&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:InkParagraph&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:InkWord&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Data&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Data&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:InkWord&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:InkParagraph&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:OE&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:OEChildren&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Outline&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#a31515;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;one:Page&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;As you can see, the new Xml format (or schema) has changed from OneNote 2003.&amp;nbsp; If you would like to explore the schemas you can download the ‘&lt;/span&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=15805380-f2c0-4b80-9ad1-2cb0c300aef9&amp;amp;displaylang=en"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;2007 Office System: XML Schema Reference&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;’. &amp;nbsp;I’ll leave it up to the reader to explore the schemas and other technical information.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;To import the ink data into OneNote you will need to use the OneNote COM API.&amp;nbsp;&amp;nbsp; In the sample program that imports the data we use a C# application and it automatically generates a interop assembly called Microsoft.Office.Interop.OneNote.&amp;nbsp; (for more information on this see &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms788684.aspx#Office2007OneNoteWhatsNew_WorkingwiththeOneNoteCOMAPI"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;this section&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; in the ‘&lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms788684.aspx"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;What’s New for Developers in OneNote 2007 (Part 1)&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; article) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The basic flow to create a new note in OneNote is this:&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN:center;" align="center"&gt;&lt;img style="WIDTH:174px;HEIGHT:508px;" height="508" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image006.gif" width="174" border="0" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Within the import application, the ink data generated by InkNoteCF is saved to the ‘Unfiled Notes’ section of OneNote.&amp;nbsp; The actual code looks like this:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Microsoft.Office.Interop.OneNote.&lt;span style="COLOR:#2b91af;"&gt;ApplicationClass&lt;/span&gt; onApp = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;ApplicationClass&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;try&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Get the path for the unfiled notes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; unfiledNotesPath;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; onApp.GetSpecialLocation(&lt;span style="COLOR:#2b91af;"&gt;SpecialLocation&lt;/span&gt;.slUnfiledNotesSection, &lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; unfiledNotesPath);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Get the ID of the unfiled notes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; UnfiledNotesID;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; onApp.OpenHierarchy(unfiledNotesPath, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; UnfiledNotesID, &lt;span style="COLOR:#2b91af;"&gt;CreateFileType&lt;/span&gt;.cftNone);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Create a new page&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; pageID;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; onApp.CreateNewPage(UnfiledNotesID, &lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; pageID, Microsoft.Office.Interop.OneNote.&lt;span style="COLOR:#2b91af;"&gt;NewPageStyle&lt;/span&gt;.npsBlankPageWithTitle);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Read the file data&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;StreamReader&lt;/span&gt; sr = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;StreamReader&lt;/span&gt;(txtInkNote.Text);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; data = sr.ReadToEnd();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(data, pageID);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Add the content to the one note page&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; onApp.UpdatePageContent(data, &lt;span style="COLOR:#2b91af;"&gt;DateTime&lt;/span&gt;.MinValue);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;catch&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; (&lt;span style="COLOR:#2b91af;"&gt;Exception&lt;/span&gt; ex)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(ex.ToString());&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;As you can see from the code, it’s not very difficult to import data into OneNote 2007.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;Changes To InkNoteCF&lt;/h3&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;When the InkNoteCF sample was first released, it only supported saving the data in OneNote 2003 format.&amp;nbsp; Since I did not have OneNote 2003 and only had 2007, I refactored the code to allow the user to save in either the OneNote 2003 or OneNote 2007 format.&amp;nbsp; In this section we will go over some of the changes done. (Note, if you are interested in importing the ink to OneNote 2003 see this &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa168020(office.11).aspx"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;article&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; on MSDN)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The first thing that was modified was the Note class.&amp;nbsp; The original one only had support for OneNote 2003 so a new NoteBase class was created to accommodate the two different versions.&amp;nbsp; The new class hierarchy is show in the following diagram.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 14" style="WIDTH:451px;HEIGHT:772px;" height="772" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image007.jpg" width="451" border="0" alt="" /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;In the main user interface, a new menu item called ‘Format’ was added to allow the user to save the ink note as either OneNote 2003 or OneNote 2007 format.&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 17" style="WIDTH:316px;HEIGHT:338px;" height="338" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image008.jpg" width="316" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;I’ll leave it up to the user to delve into the code and to see how the saving code works.&amp;nbsp; In a nutshell, it just calls the XmlDocument.Save() method.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;Running the Code&lt;/h3&gt;
&lt;p class="MsoNormal"&gt;After all this background information you are probably thinking, what is the result?&amp;nbsp; Well, here are the screen shots of the application on the device and in OneNote 2007.&lt;/p&gt;
&lt;p class="MsoNormal" style="TEXT-ALIGN:center;" align="center"&gt;&lt;img id="Picture 23" style="WIDTH:480px;HEIGHT:640px;" height="640" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image009.jpg" width="480" border="0" alt="" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="TEXT-ALIGN:center;" align="center"&gt;&lt;img id="Picture 26" style="WIDTH:539px;HEIGHT:453px;" height="453" src="http://community.opennetcf.com/blogs/cf/200709/Sharing%20Windows%20Mobile%20Ink%20with%20the%20Desktop_files/image010.jpg" width="539" border="0" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178752135" name="_Toc178752135"&gt;&lt;/a&gt;What’s Next&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE:10.5pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;From here the Mobile Ink Library is in a good state to be used in managed applications.&amp;nbsp; We are hoping to improve it some more by wrapping some of the WISP Lite interfaces and align the object model more closely with the desktop.&amp;nbsp; At this point we have no plans to do that but invite the community to contribute to the project.&amp;nbsp; You can download the source code for Mobile Ink Library and the Samples at &lt;/span&gt;&lt;a href="http://www.opennetcf.com/opensource/mobileink.ocf"&gt;&lt;span style="FONT-SIZE:10.5pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;www.opennetcf.com/opensource/mobileink.ocf&lt;/span&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:10.5pt;LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178752136" name="_Toc178752136"&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;The new WISP Lite API available in Windows Mobile 6 gives the native developer the ability to ‘ink enable’ a Windows Mobile application.&amp;nbsp; Using the Mobile Ink Library from OpenNETCF, .NET Compact Framework developers can now also ‘ink enable’ their applications.&amp;nbsp; In this article we discussed how using the Mobile Ink Library, you can easily share ink data with a custom application or with OneNote 2007.&amp;nbsp; Have fun Inking!&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=30" width="1" height="1"&gt;</content><author><name>marteaga</name><uri>http://community.opennetcf.com/members/marteaga.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="WISP Lite" scheme="http://community.opennetcf.com/articles/cf/archive/tags/WISP+Lite/default.aspx" /><category term="Mobile Ink Library" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Mobile+Ink+Library/default.aspx" /></entry><entry><title>Using the OpenNETCF Mobile Ink Library for Windows Mobile 6</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/09/28/using-the-opennetcf-mobile-ink-library-for-windows-mobile-6.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/09/28/using-the-opennetcf-mobile-ink-library-for-windows-mobile-6.aspx</id><published>2007-09-28T19:17:00Z</published><updated>2007-09-28T19:17:00Z</updated><content type="html">Mark Arteaga &lt;br /&gt;OpenNETCF Consulting&lt;br /&gt;September 2007&lt;a class="" title="_Toc176367341" name="_Toc176367341"&gt;&lt;/a&gt; 
&lt;div class="Section1"&gt;
&lt;p class="MsoToc1"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" align="middle" border="0" alt="" /&gt;&lt;a class="" title="Download the Source" href="http://www.opennetcf.com/downloads/download.aspx?s=OpenNETCFMobileInkLibrary-1.0" target="_blank"&gt;Download the Source Code&lt;/a&gt;&lt;br /&gt;&lt;img height="30" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;&lt;a class="" title="Download the PDF" href="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library.pdf" target="_blank"&gt;Download the PDF&lt;/a&gt;&lt;/p&gt;
&lt;p class="MsoToc1"&gt;Contents&lt;/p&gt;
&lt;p class="MsoToc2"&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178579247"&gt;Introduction&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178579248"&gt;Technical Overview&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178579256"&gt;Mobile Ink Library Custom Controls&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178579265"&gt;Samples Available with the Mobile Ink Library&lt;/a&gt;&lt;span class="MsoHyperlink"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Toc178579271"&gt;Conclusion&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a class="" title="_Toc178579247" name="_Toc178579247"&gt;&lt;/a&gt;Introduction&lt;/h2&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;With the recent release of the Mobile Ink Library for Windows Mobile 6, some people are probably thinking &amp;#39;well what can I use that for&amp;#39;.&amp;nbsp; In this article we will be going over some technical information and some possible uses for inking on the Windows Mobile 6 platform. &lt;/p&gt;
&lt;h2 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579248" name="_Toc178579248"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367342" name="_Toc176367342"&gt;&lt;/a&gt;Technical Overview&lt;/h2&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579249" name="_Toc178579249"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367343" name="_Toc176367343"&gt;&lt;/a&gt;Windows Mobile 6 Inking&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;In the latest release of Windows Mobile, there is a new API called Windows Mobile Ink.&amp;nbsp; What is Windows Mobile Ink?&amp;nbsp; Where does it come from? Why do you need it?&amp;nbsp;In a nutshell, Windows Mobile Ink&amp;nbsp;is a new Inking API only available for the Windows Mobile 6 platform called WISP Lite.&amp;nbsp; It is&amp;nbsp;based on Windows Inking Services Platform (WISP) for the Tablet PC.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Desktop developers have managed classes available under the Microsoft.Ink namespace to allow them to develop managed applications to take advantage of &amp;#39;inking&amp;#39; features available on Tablet PC.&amp;nbsp; This article&amp;nbsp;does not deal with the desktop so I&amp;#39;ll leave it up to the user to &lt;a href="http://search.live.com/results.aspx?q=microsoft.ink&amp;amp;src=IE-SearchBox"&gt;&lt;span style="COLOR:windowtext;TEXT-DECORATION:none;"&gt;search&lt;/span&gt;&lt;/a&gt; the many articles available on inking on the Tablet PC. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The Windows Mobile 6 SDK contains some examples of using WISP Lite with native code.&amp;nbsp; Unfortunately if you are a managed&amp;nbsp;developer, there are no managed classes available for your .NET Compact Framework applications.&amp;nbsp; The&amp;nbsp;Mobile Ink Library addresses this issue and provides a library of classes which wrap the COM interfaces and&amp;nbsp;the controls that are available on the Windows Mobile 6 platform.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579250" name="_Toc178579250"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367344" name="_Toc176367344"&gt;&lt;/a&gt;Differences from the Desktop and Device&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The Mobile Ink Library and WISP Lite allows a developer to add inking functionality to their Windows Mobile application.&amp;nbsp; WISP Lite (as the name implies) is a &amp;#39;lighter&amp;#39; version or a subset of WISP available on the desktop.&amp;nbsp; For the managed desktop developer, there is the Microsoft.Ink namespace which provides inking capabilities in your .NET Framework application.&amp;nbsp; For the native developer there is also a COM API available to add inking capabilities to a native application.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Currently for inking capabilities on the Windows Mobile 6 platform there are only COM interfaces and a &amp;#39;windowed control&amp;#39; named InkCanvas available to native developers.&amp;nbsp; Managed developers using .NET Compact Framework&amp;nbsp;don&amp;#39;t have any managed classes available but&amp;nbsp;can wrap the COM interfaces and the InkCanvas control using version 2 of .NET Compact Framework.&amp;nbsp;&amp;nbsp;The Mobile Ink Library has already done this and is available under the OpenNETCF.WindowsMobile.Ink namespace.&amp;nbsp; This gives the managed developer the ability to take advantage of this new APIs available.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Both the desktop and the Windows Mobile versions of inking APIs allow the developer to save the ink in a format called Ink Serialized Format or ISF.&amp;nbsp; The ISF data output, which can be saved as Base64 or Binary, is compatible on both the desktop and mobile device.&amp;nbsp; If you try to open an ISF stream on mobile device that was saved on the desktop, the mobile device will ignore any properties in the stream that are not supported on Windows Mobile but still preserve the properties when saved again.&amp;nbsp; See this &lt;a href="http://msdn2.microsoft.com/en-us/library/bb431844.aspxhttp:/msdn2.microsoft.com/en-us/library/bb431844.aspx"&gt;page&lt;/a&gt; for more details on the differences between the desktop and device.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579251" name="_Toc178579251"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367345" name="_Toc176367345"&gt;&lt;/a&gt;COM Interfaces&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;There are various COM interfaces available for Windows Mobile Ink and for details on using it with native code see &amp;#39;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb416406.aspx"&gt;Using the Automation Library with Windows Mobile Ink&lt;/a&gt;&amp;#39;.&amp;nbsp; The Mobile Ink Library&amp;nbsp;wraps the appropriate interfaces to allow a managed developer to ink enable a .NET Compact Framework application.&amp;nbsp;&amp;nbsp;Two interfaces that are primarily used and&amp;nbsp;will be covering&amp;nbsp;next are IInkDisp&amp;nbsp;and IInkOverlay.&lt;/p&gt;
&lt;h3&gt;&lt;a class="" title="_Toc178579252" name="_Toc178579252"&gt;&lt;/a&gt;&lt;a class="" title="_IInkOverlay" name="_IInkOverlay"&gt;&lt;/a&gt;IInkOverlay&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;An IInkOverlay object is used to attach to a window (or control) using the IInkOverlay.hWnd property.&amp;nbsp; When you &amp;#39;attach&amp;#39; a window to an IInkOverlay object, the window becomes &amp;#39;ink enabled&amp;#39; and allows the collection of ink data.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;IInkOverlay also allows you to change the size, shape and color of the ink using the IInkOverlay.DefaultDrawingAttributes property.&amp;nbsp; The following example changes the size of the pen width using a TrackBar.Value property.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#2b91af;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;IInkDrawingAttributes&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; attrs = overlay.DefaultDrawingAttributes;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;attrs.Width = (&lt;span style="COLOR:blue;"&gt;float&lt;/span&gt;)trackBar1.Value;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;overlay.DefaultDrawingAttributes = attrs;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:7.5pt;LINE-HEIGHT:normal;"&gt;An example use of IInkOverlay is attaching it to a PictureBox&amp;nbsp;and adding ink notes to an image.&amp;nbsp; The following code sample uses the OpenNETCF.WindowsMobile.Ink.Ink class to achieve this:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#2b91af;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;PictureBox&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; pb = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;PictureBox&lt;/span&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;//Create a new InkOverlay object&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;OpenNETCF.WindowsMobile.Ink.&lt;span style="COLOR:#2b91af;"&gt;Ink&lt;/span&gt; ink = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; OpenNETCF.WindowsMobile.Ink.&lt;span style="COLOR:#2b91af;"&gt;Ink&lt;/span&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;//We need to set the handle (or control) the inkoverlay object is bound to&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;ink.IInkOverlay.hWnd = pb.Handle;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;ink.IInkOverlay.Enabled = &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;To change the editing mode of the Ink object the EditingMode property can be set with one of the following values:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;enum&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;InkOverlayEditingMode&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ink = 0,&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delete = 1,&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select = 2&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;IInkOverlay exposes a property called Ink&amp;nbsp;which gets or sets the IInkDisp object that is associated with the IInkOverlay object.&lt;/p&gt;
&lt;h3&gt;&lt;a class="" title="_Toc178579253" name="_Toc178579253"&gt;&lt;/a&gt;IInkDisp&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;IInkDisp is responsible for collecting the ink strokes from a user.&amp;nbsp; It also has&amp;nbsp;the ability to&amp;nbsp;Save() and Load()&amp;nbsp;the ink strokes collected by an IInkDisp.&amp;nbsp; To create an instance of IInkDisp, use OpenNETCF.WindowsMobile.Ink.InkDisp class has one static method called CreateInstance().&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Usually&amp;nbsp;you will want to create a new IInkDisp when you&amp;nbsp;want to clear existing ink in an IInkOverlay.Ink.&amp;nbsp; An example of this is:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:#2b91af;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;IInkDisp&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; inkDisp = &lt;span style="COLOR:#2b91af;"&gt;InkDisp&lt;/span&gt;.CreateInstance();&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;overlay.Enabled = &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;overlay.Ink = inkDisp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;overlay.Enabled = &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Note, to set the IInkOverlay.Ink property, you must first set IInkOverlay.Enabled to false and then once you set the IInkOverlay.Ink property set the IInkOverlay.Enabled back to true.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;When saving the ink strokes, the Save() method returns a byte[]&amp;nbsp; and there are four possible options defined in OpenNETCF.WindowsMobile.Ink.InkPersistenceFormat:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;InkSerializedFormat - The ink data using ISF.&amp;nbsp; This is the most compact representation of ink data. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Base64InkSerializedFormat - The ink data using ISF and Base64 encoded. &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Gif - The ink data in Graphics Interchange Format (Gif) &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Base64Gif - The ink data Graphics Interchange Format (Gif) and Base64 encoded&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;These options allow the developer to save in various formats depending on their application requirements.&amp;nbsp; For example, if you are emailing the collected ink, the receiver may not be able to render the ISF format so you will probably want to send it as a Gif image attached to the email.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;IInkDisp has a property call ExtendedProperties which allows the you to save custom data within the ink data.&amp;nbsp; For example,&amp;nbsp;using ExtendedProperties you can &amp;#39;embedded&amp;#39; some data to know when the ink data was last saved.&amp;nbsp; One caveat is ExtendedProperties are only persisted when saving as either InkSerializedFormat&amp;nbsp;or Base64InkSerializedFormat so if you save as a Gif or Base64Gif, this data will be lost.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;That summarizes IInkOverlay and IInkDisp which are probably the two main classes needed for inking.&amp;nbsp; I&amp;#39;ll leave it up to the reader to explore some of the other methods&amp;nbsp;and properties&amp;nbsp;available in these interfaces and some of the other interfaces available.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579254" name="_Toc178579254"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367346" name="_Toc176367346"&gt;&lt;/a&gt;InkCanvas Control&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The InkCanvas control is a windowed control and allows the developer to avoid using the COM Interfaces for inking in their application.&amp;nbsp; In addition to the COM Interfaces wrapped by Mobile Ink Library, the library also includes a managed wrapper appropriately called InkCanvas (found under OpenNETCF.WindowsMobile.Ink.InkCanvas).&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkCanvas simplifies capturing ink within your application.&amp;nbsp; It uses windows messages to request operations and notify the user of any changes like adding or deleting ink.&amp;nbsp; If using the IInkDisp COM object is desired, the OpenNETCF.WindowsMobile.Ink.InkCanvas.Ink property can be used.&amp;nbsp; InkCanvas also has the following properties which may be useful&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Mode - Gets or sets the editing mode &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Ink - Gets the IInkDisp object &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;BackColor - Gets or Sets the background color &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;ZoomLevel - Gets or sets the zoom level &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;CanvasSize - Gets or sets the canvas size &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;RecognizedText - Gets the&amp;nbsp;recognized ink as text &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-LEFT:39.75pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;PenStyle - Gets or sets the style of pen to use for example pen or highlighter&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;There are also various methods available in the InkCanvas control which is pretty self explanatory so I&amp;#39;ll leave it up to the reader to explore.&amp;nbsp;&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579255" name="_Toc178579255"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367347" name="_Toc176367347"&gt;&lt;/a&gt;&lt;a class="" title="_Ink_Recognition" name="_Ink_Recognition"&gt;&lt;/a&gt;Ink Recognition &lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;One of the great benefits of the Windows Mobile Ink&amp;nbsp;API is the ability to convert the ink data to a text string via ink recognition.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The following code sample will convert ink data to a text string using the COM objects:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;private&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:#2b91af;"&gt;Ink&lt;/span&gt; m_ink;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; ToString()&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Get the appropriate COM objects required.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IInkDisp&lt;/span&gt; disp = m_ink.InkDisp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IInkStrokes&lt;/span&gt; strokes = disp.Strokes;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IInkRecognitionResult&lt;/span&gt; results = strokes.RecognitionResult;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Get the recognized string.&amp;nbsp; An alternate way of doing this is strokes.ToString()&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; ret = results == &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt; ? &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt; : results.TopString;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Release the COM objects&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (results != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.ReleaseComObject(results);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.ReleaseComObject(strokes);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.ReleaseComObject(disp);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Return the recognized text&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; ret;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;If you use the InkCanvas control the RecognizedText property can be used.&amp;nbsp; Internally the InkCanvas control does the following to recognize the ink data:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; RecognizedText&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; Ink.Strokes.RecognitionResult.TopString;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; Interfaces.&lt;span style="COLOR:#2b91af;"&gt;IInkDisp&lt;/span&gt; Ink&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (OpenNETCF.Windows.Forms.&lt;span style="COLOR:#2b91af;"&gt;StaticMethods&lt;/span&gt;.IsDesignTime)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IntPtr&lt;/span&gt; pInk;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.SendMessage(childHandle, (&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;)&lt;span style="COLOR:#2b91af;"&gt;ICM&lt;/span&gt;.GETINK, 0, &lt;span style="COLOR:blue;"&gt;out&lt;/span&gt; pInk);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (pInk == &lt;span style="COLOR:#2b91af;"&gt;IntPtr&lt;/span&gt;.Zero)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; (Interfaces.&lt;span style="COLOR:#2b91af;"&gt;IInkDisp&lt;/span&gt;)&lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.GetObjectForIUnknown(pInk);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Essentially both methods would produce the same results for the same ink data.&lt;/p&gt;
&lt;h2 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579256" name="_Toc178579256"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367348" name="_Toc176367348"&gt;&lt;/a&gt;Mobile Ink Library Custom Controls&lt;/h2&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The Mobile Ink Library consists of four controls to make it easier for the developer to ink enable a .NET Compact Framework application.&amp;nbsp; Using the IInkOverlay is pretty straight forward, but to simplify the life of the developer various controls were created to ink enable .NET Compact Framework applications using Windows Mobile 6.0.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579257" name="_Toc178579257"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367349" name="_Toc176367349"&gt;&lt;/a&gt;InkControlBase&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkControlBase is the abstract base class in which the InkRecognizer, InkPicture and InkSignature inherit from.&amp;nbsp; The following is the class diagram of the control:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img style="WIDTH:259px;HEIGHT:482px;" height="482" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image021.jpg" width="259" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;As you can see from the diagram&amp;nbsp;InkControlBase inherits from System.Windows.Forms.Control.&amp;nbsp; &amp;#39;Inking&amp;#39; the control is enabled by the Ink property which wraps the IInkOverlay interface (for more information on IInkOverlay see the &lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_IInkOverlay"&gt;above&lt;/a&gt;).&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Since IInkOverlay requires a handle to the window (or control) to attach to, we override the OnHandleCreated() in the InkControlBase class to attach the control.&amp;nbsp; The following code is used to accomplish this:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;protected&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; OnHandleCreated(&lt;span style="COLOR:#2b91af;"&gt;EventArgs&lt;/span&gt; e)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.OnHandleCreated(e);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (&lt;span style="COLOR:#2b91af;"&gt;StaticMethods&lt;/span&gt;.IsRunTime)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (m_inkOverlay == &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Create the IInkOverlay object&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_inkOverlay = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Ink&lt;/span&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Listen for all stroke events&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_inkOverlay.IInkOverlay.SetEventInterest(&lt;span style="COLOR:#2b91af;"&gt;InkCollectorEventInterest&lt;/span&gt;.Stroke, &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//We need to set the handle (or control) the inkoverlay object is bound to&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_inkOverlay.IInkOverlay.hWnd = &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.HandleInternal;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_inkOverlay.IInkOverlay.Enabled = &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;You will notice the following line:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;m_inkOverlay.IInkOverlay.hWnd = &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.HandleInternal;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;HandleInternal is an internal virtual property and returns the Handle of the InkControlBase control used to attach to the IInkOverlay.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;///&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;///&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; Gets the internal handle to associate the IInkOverlay object with&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;///&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;internal&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;virtual&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;IntPtr&lt;/span&gt; HandleInternal&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.Handle;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Classes inheriting from InkControlBase have the option to override this property to return a different handle.&amp;nbsp; We will visit this again when we discuss the remaining controls.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkControlBase provides all the basic functionality such as Clear(), Open() and Save() methods.&amp;nbsp; These methods internally use the Ink&amp;nbsp;property to make the required calls to IInkOverlay.&amp;nbsp; &lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579258" name="_Toc178579258"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367350" name="_Toc176367350"&gt;&lt;/a&gt;InkRecognizer&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkRecognizer class was created to allow the developer to recognize ink inputted by a user into plain text and inherits from InkControlBase.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 19" style="WIDTH:451px;HEIGHT:482px;" height="482" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image022.jpg" width="451" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;From the class diagram, you will see that InkRecognizer does not do much except&amp;nbsp;override the ToString() method.&amp;nbsp; The ToString() method will return the text string that is recognized by the IInkOverlay object using the following code:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; ToString()&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (&lt;span style="COLOR:#2b91af;"&gt;StaticMethods&lt;/span&gt;.IsDesignTime || &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.InkOverlay == &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.ToString();&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;else&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Get the appropriate COM objects required.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IInkDisp&lt;/span&gt; disp = Ink.InkDisp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IInkStrokes&lt;/span&gt; strokes = disp.Strokes;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;IInkRecognitionResult&lt;/span&gt; results = strokes.RecognitionResult;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Get the recognized string.&amp;nbsp; An alternate way of doing this is strokes.ToString()&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; ret = results == &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt; ? &lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt; : results.TopString;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Release the COM objects&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (results != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.ReleaseComObject(results);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.ReleaseComObject(strokes);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;.ReleaseComObject(disp);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//Return the recognized text&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; ret;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;From the code above you will notice that Ink property is used to access the IInkDisp, IInkStrokes and IInkRecognitionResults to return the recognized text.&amp;nbsp; (For more information on text recognition see the &lt;a href="http://community.opennetcf.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=NewPost#_Ink_Recognition"&gt;above&lt;/a&gt;).&amp;nbsp; The BasicRecognitionCF sample&amp;nbsp;demonstrates the use of the InkRecognizer control.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579259" name="_Toc178579259"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367351" name="_Toc176367351"&gt;&lt;/a&gt;InkPicture&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkPicture control allows the developer to add ink to a picture using the standard System.Windows.Forms.PictureBox control.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 22" style="WIDTH:427px;HEIGHT:482px;" height="482" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image023.jpg" width="427" border="0" alt="" /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The InkPicture control is not as straight forward as the InkRecognizer.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The first difference is InkPicture overrides HandleInternal.&amp;nbsp; If you recall, HandleInternal provides the handle to which the IInkOverlay object will be attached to.&amp;nbsp; InkPicture internally has an m_pictureBox field which is the standard PictureBox control used to display an image and we use the m_pictureBox.Handle to attach to the IInkOverlay object.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The InkPicture control exposes the internal PictureBox control as a property to allow the developer to modify any properties for the picture box.&amp;nbsp; It also exposes an Image property to get or set the image that is displayed in the PictureBox.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579260" name="_Toc178579260"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367352" name="_Toc176367352"&gt;&lt;/a&gt;InkSignature&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Capturing signatures is a very common requirement for Windows Mobile line of business applications and using and using the Windows Mobile Ink API&amp;nbsp;(or WISP Lite) is a perfect solution.&amp;nbsp; Since the InkPicture control has the main requirements for capturing signatures (which is really just capturing ink data) it can be used as the base class for InkSignature.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 25" style="WIDTH:451px;HEIGHT:634px;" height="634" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image024.jpg" width="451" border="0" alt="" /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Since this is a signature control, we may want to give some sort of indication to the user to sign.&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp; &lt;/span&gt;To do this we can add an image to the control using the Image property.&amp;nbsp; Below is an example of what that could possibly look like:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 5" style="WIDTH:240px;HEIGHT:320px;" height="320" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image025.gif" width="240" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The InkSignature control also exposes a FirstName, LastName and DateSigned property.&amp;nbsp; These class properties are saved as ExtendedProperties within the Ink Serialized&amp;nbsp;Format&amp;nbsp;(ISF) file when the signature data is saved.&amp;nbsp;Be aware that these properties are only saved when the ink data is saved using ISF and won&amp;#39;t be saved if saved to a GIF file.&amp;nbsp; The InkSerializationCF Sample&amp;nbsp;demonstrates the use of the InkSignature control.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579261" name="_Toc178579261"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367353" name="_Toc176367353"&gt;&lt;/a&gt;InkControlBase Workarounds&amp;nbsp;&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;During the development of these controls, it was found that IInkOverlay behaved differently in managed code than it did in native code.&amp;nbsp; Whenever a user started inking on the signature control, the InkSignature control could never lose focus by tapping on any part of the screen (for example the Textbox).&amp;nbsp; Specifically, the Capture property of&amp;nbsp;the control was set to True whenever a user started inking which caused other controls to not receive any Click events.&amp;nbsp; It was also noticed that the InkControlBase control would never receive focus when clicked on because of IInkOverlay.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;To work around this a workaround was implemented in the OnMouseDown and OnMouseUp of the InkControlBase.&amp;nbsp; &lt;/p&gt;
&lt;h4 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579262" name="_Toc178579262"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367354" name="_Toc176367354"&gt;&lt;/a&gt;Focus Issue&lt;/h4&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;First we&amp;#39;ll look at OnMouseDown which resolves the &amp;#39;focus&amp;#39; issue:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;protected&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;override void&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;OnMouseDown(&lt;span style="COLOR:#2b91af;"&gt;MouseEventArgs&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;e)&lt;br /&gt;{&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;base&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;.&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;OnMouseDown(e);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;if&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.ClientRectangle.Contains(e.X, e.Y))&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;OnMouseDownInternal(e);&lt;/span&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;From the code above you can see that on mouse down we check to see if we are in the bounds of the control, if we are we call OnMouseDownInternal().&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;internal&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;virtual&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; OnMouseDownInternal(&lt;span style="COLOR:#2b91af;"&gt;MouseEventArgs&lt;/span&gt; e)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.BoundingControl.Focus();&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;OnMouseDownInternal() will call the Foucs() method on the BoundingControl.&amp;nbsp; In the case of InkRecognizer it calls the InkControlBase implementation which returns this.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;internal&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;virtual&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Control&lt;/span&gt; BoundingControl&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;In the case of InkPicture and InkSignature, we override the BoundingControl property and return m_pictureBox.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;internal&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Control&lt;/span&gt; BoundingControl&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.m_pictureBox;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;This allows us to set focus to the underlying control and still have the control fire off events like GotFocus.&lt;/p&gt;
&lt;h4 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579263" name="_Toc178579263"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367355" name="_Toc176367355"&gt;&lt;/a&gt;Capture Issue&lt;/h4&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The next issue faced was the Capture issue.&amp;nbsp; It seemed IInkOverlay always set Capture to true for the bounded control.&amp;nbsp; To work around this issue we had to override OnMouseUp as follows:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;protected&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; OnMouseUp(&lt;span style="COLOR:#2b91af;"&gt;MouseEventArgs&lt;/span&gt; e)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; (!&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.ClientRectangle.Contains(e.X, e.Y))&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OnMouseUpInternal(e);&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.OnMouseDown(e);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Again from the above code you can see that we call OnMouseUpInternal() where we set the Capture property to false and then send a &amp;#39;manual tap&amp;#39; so the user does not have to tap the screen twice.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;internal&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;virtual&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; OnMouseUpInternal(&lt;span style="COLOR:#2b91af;"&gt;MouseEventArgs&lt;/span&gt; e)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//HACK When using the IInkOverlay object in managed&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//code seems that the control Capture property is set to true.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//When trying to click outside the bounds of the&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//control (ie a button) the control would not&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//receive the mouse click&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.BoundingControl.Capture = &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SendTap(&lt;span style="COLOR:#2b91af;"&gt;Control&lt;/span&gt;.MousePosition.X, &lt;span style="COLOR:#2b91af;"&gt;Control&lt;/span&gt;.MousePosition.Y);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The SendTap() method makes a native call to &lt;a href="http://msdn2.microsoft.com/en-us/library/aa932376.aspx"&gt;&lt;span style="COLOR:windowtext;TEXT-DECORATION:none;"&gt;mouse_event&lt;/span&gt;&lt;/a&gt; to manually send another tap to the screen since the first tap (or click) was consumed by the InkBaseControl.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;internal&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; SendTap(&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; x, &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; y)&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.mouse_event(&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;MOUSEEVENTF&lt;/span&gt;.LEFTDOWN | &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;MOUSEEVENTF&lt;/span&gt;.ABSOLUTE,&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;)((65535 / &lt;span style="COLOR:#2b91af;"&gt;Screen&lt;/span&gt;.PrimaryScreen.Bounds.Width) * x),&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;)((65535 / &lt;span style="COLOR:#2b91af;"&gt;Screen&lt;/span&gt;.PrimaryScreen.Bounds.Height) * y),&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0,&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.mouse_event(&lt;span style="COLOR:#2b91af;"&gt;NativeMethods&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;MOUSEEVENTF&lt;/span&gt;.LEFTUP, 0, 0, 0, 0);&lt;br /&gt;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579264" name="_Toc178579264"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367356" name="_Toc176367356"&gt;&lt;/a&gt;InkCanvas&lt;/h3&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;The InkCanvas control was discussed briefly in the technical overview but we will go through it again since it&amp;#39;s a custom control part of the Mobile Ink Library.&amp;nbsp; The InkCanvas control is a managed wrapper to the native InkCanvas control available on Windows Mobile 6.&amp;nbsp;&amp;nbsp;The InkCanvas control gives you the ability to add inking capabilities to your&amp;nbsp;Compact Framework application on the Windows Mobile 6 platform without the need to use any of the COM interfaces.&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Here is the class diagram of InkCanvas:&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;TEXT-ALIGN:center;" align="center"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 6" style="WIDTH:444px;HEIGHT:814px;" height="814" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image026.gif" width="444" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;From the above class diagram you can see there are three different modes that the InkCanvas can be set to.&amp;nbsp; &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;INK - Sets the InkCanvas to inking mode and allows the collection of ink data &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;SELECT - Sets the InkCanvas control select ink strokes collected &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;DELETE - Sets the InkCanvas to delete ink strokes as the user taps on the stroke&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;There is also a PenStyle property which allows you to change the size, color, width and pen type of the stroke being collected.&amp;nbsp; If you need to interact with the IInkDisp interface, you can also use the Ink property and use the COM interfaces available.&amp;nbsp; The main method of communication with the native InkCanvas is via windows messages.&amp;nbsp; Since the&amp;nbsp;InkCanvas control inherits from the OpenNETCF.Windows.Forms.Control2 class, Control2&amp;nbsp;helps simplify the creation of native control and capture any messages such as StrokeAdded.&amp;nbsp;This allows us to raise relevant events such as StrokeAdded, StrokeDeleted and CharacterAdded.&amp;nbsp; The InkNotesCF Sample demonstrates the use of InkCanvas control.&lt;/p&gt;
&lt;h2 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579265" name="_Toc178579265"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367357" name="_Toc176367357"&gt;&lt;/a&gt;Samples Available with the Mobile Ink Library&lt;/h2&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;Also included with the installation&amp;nbsp;are five sample applications demonstrating the use of the library.&amp;nbsp; The following is a brief description of the samples.&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579266" name="_Toc178579266"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367358" name="_Toc176367358"&gt;&lt;/a&gt;InkControlDemo&lt;/h3&gt;
&lt;table class="MsoNormalTable" style="WIDTH:506.25pt;" cellspacing="0" cellpadding="0" class="MsoNormalTable"&gt;

&lt;tr&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:315.75pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkControlDemo demonstrates the various features of the InkCanvas control available in the Mobile Ink Library.&amp;nbsp; It demonstrates how to:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Add, select and delete ink data &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Change the color of the ink canvas, back color and pen color &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Change the width of the pen &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Text Recognition &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Extracting an image of the ISF ink data&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:189pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 13" style="WIDTH:240px;HEIGHT:320px;" height="320" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image027.gif" width="240" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579267" name="_Toc178579267"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367359" name="_Toc176367359"&gt;&lt;/a&gt;InkObjDemo&lt;/h3&gt;
&lt;table class="MsoNormalTable" style="WIDTH:501.75pt;" cellspacing="0" cellpadding="0" class="MsoNormalTable"&gt;

&lt;tr&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:317.25pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkObjDemo demonstrates the following:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;How to use the IInkOverlay COM interface within a managed application &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;How to save the ink data as Ink Serialized Format (ISF) from the IInkOverlay COM Object &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;How to load and Ink Serialized Format file into an IInkOverlay object &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Clearing the ink collected by IInkOverlay &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Changing the width of the pen for the ink&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:183pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 14" style="WIDTH:240px;HEIGHT:320px;" height="320" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image028.gif" width="240" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579268" name="_Toc178579268"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367360" name="_Toc176367360"&gt;&lt;/a&gt;BasicRecognitionCF&lt;/h3&gt;
&lt;table class="MsoNormalTable" style="WIDTH:500.25pt;" cellspacing="0" cellpadding="0" class="MsoNormalTable"&gt;

&lt;tr&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:318pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;BasicRecognitionCF was ported from the BasicRecognition native sample available with the Windows Mobile 6 Professional SDK.&amp;nbsp; It allows a user to input text with the stylus, and recognize the text.&amp;nbsp; It demonstrates the following:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Using the InkRecognizer custom control &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Saving and Loading ISF files &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Ink recognition&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:180.75pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 15" style="WIDTH:240px;HEIGHT:320px;" height="320" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image029.gif" width="240" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579269" name="_Toc178579269"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367361" name="_Toc176367361"&gt;&lt;/a&gt;InkSerializationCF&lt;/h3&gt;
&lt;table class="MsoNormalTable" style="WIDTH:499.5pt;" cellspacing="0" cellpadding="0" class="MsoNormalTable"&gt;

&lt;tr&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:317.25pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkSerializationCF was ported from the InkSerialzation native sample available with the Windows Mobile 6 Professional SDK.&amp;nbsp;&amp;nbsp; It allows a user to sign on a region and save the signature along with the persons name in the ISF file.&amp;nbsp; It demonstrates using the following:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Using the InkSignature custom control &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Saving and loading a signature file (ISF file) &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Embedding ExtendedProperties within an ISF binary stream&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:180.75pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 16" style="WIDTH:240px;HEIGHT:320px;" height="320" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image025.gif" width="240" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc178579270" name="_Toc178579270"&gt;&lt;/a&gt;&lt;a class="" title="_Toc176367362" name="_Toc176367362"&gt;&lt;/a&gt;InkNotesCF&lt;/h3&gt;
&lt;table class="MsoNormalTable" style="WIDTH:499.5pt;" cellspacing="0" cellpadding="0" class="MsoNormalTable"&gt;

&lt;tr&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:317.25pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;InkNotesCF was ported from the InkNotes native sample available with the Windows Mobile 6 Professional SDK&amp;nbsp;.&amp;nbsp;&amp;nbsp; It allows a user to view and edit ink notes. These ink notes can also be imported to OneNote 2007&amp;nbsp;or 2003&amp;nbsp;on the desktop.&amp;nbsp; It demonstrates using the following:&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;InkCanvas control &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Changing the pen used for inking &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Erasing Ink &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Selecting Ink &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Zooming in and out &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Saving and loading ISF files &lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="MARGIN:7.5pt 0cm 7.5pt 36pt;TEXT-INDENT:-18pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-FAMILY:Symbol;"&gt;·&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Emailing the note as a GIF attachment&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td class="" style="PADDING-RIGHT:1.5pt;PADDING-LEFT:1.5pt;PADDING-BOTTOM:1.5pt;WIDTH:180.75pt;PADDING-TOP:1.5pt;"&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;img id="Picture 17" style="WIDTH:240px;HEIGHT:320px;" height="320" src="http://community.opennetcf.com/blogs/cf/200709/Mobile%20Ink%20Library_files/image030.gif" width="240" border="0" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p class="MsoNormal" style="MARGIN:7.5pt 0cm;LINE-HEIGHT:normal;"&gt;&lt;span style="FONT-SIZE:10.5pt;FONT-FAMILY:&amp;#39;Trebuchet MS&amp;#39;,&amp;#39;sans-serif&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 style="LINE-HEIGHT:normal;"&gt;&lt;a class="" title="_Toc176367363" name="_Toc176367363"&gt;&lt;/a&gt;&lt;a class="" title="_Toc178579271" name="_Toc178579271"&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;In this article we took a look at the Windows Mobile Ink API for Windows Mobile 6 and the OpenNETCF Mobile Ink Library.&amp;nbsp; The Mobile Ink Library opens the doors to .NET Compact Framework developers to ink enable their Windows Mobile 6 applications.&amp;nbsp; In the next article we’ll look at using the same Ink Serialized Format (ISF) data on both&amp;nbsp; a Windows Mobile 6 application and a desktop application.&lt;/p&gt;&lt;/div&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=29" width="1" height="1"&gt;</content><author><name>marteaga</name><uri>http://community.opennetcf.com/members/marteaga.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="WISP Lite" scheme="http://community.opennetcf.com/articles/cf/archive/tags/WISP+Lite/default.aspx" /><category term="Mobile Ink Library" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Mobile+Ink+Library/default.aspx" /></entry><entry><title>Improving Data Access Performance with Data Caching</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/09/21/improving-data-access-performance-with-data-caching.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/09/21/improving-data-access-performance-with-data-caching.aspx</id><published>2007-09-21T16:50:00Z</published><updated>2007-09-21T16:50:00Z</updated><content type="html">&lt;p&gt;Chris Tacke&lt;br /&gt;OpenNETCF Consulting&lt;br /&gt;September 2007&lt;/p&gt;
&lt;p&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" align="middle" border="0" alt="" /&gt;&lt;a href="http://www.opennetcf.com/downloads/download.aspx?s=TableCache" title="Download the Source" target="_blank"&gt;Download the Source Code&lt;/a&gt;&lt;br /&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" height="30" alt="" /&gt;&lt;a href="http://community.opennetcf.com/blogs/cf/200709/DataCaching.pdf" class="" title="Download the PDF" target="_blank"&gt;Download the PDF&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Performance of &amp;nbsp;the data access layer of a mobile or embedded application is often viewed by developers in very broad strokes.&amp;nbsp; When we begin designing a solution we consider the performance versus benefits of using DataReaders,&amp;nbsp; DataAdapters, DataSets and the like.&amp;nbsp; Most often we just make an early determination based on what our expected use and the generally accepted &amp;quot;best practice&amp;quot; is and then move on without much further thought.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Traditionally if we only wanted to ever read the data in a non-scrollable cursor, we&amp;#39;d use a DataReader.&amp;nbsp; If we want to alter the data we&amp;#39;d use a DataSet.&amp;nbsp; Version 2.0 of the Compact Framework brought the wonderful &amp;quot;blended&amp;quot; use DataAdapter, and many developers migrated to it and considered the variable of data access performance to be largely out of their hands beyond that point.&lt;/p&gt;
&lt;p&gt;A recent plant floor automation system project that we worked on was a stark reminder that such assumptions are not true, and that performance considerations need to be looked at throughout the development of any solution.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Data Access as a Bottleneck&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Like many projects, we didn&amp;#39;t really start to discover show-stopping performance problems in our recent endeavor until we were getting close to delivery of a full working system.&amp;nbsp; Early tests during development usually miss the full impact of all of the interactions of a full running system, and it&amp;#39;s really hard, if not impossible, to guess what the actual execution performance of any solution will be until all of the major pieces ar in place and cooperating.&amp;nbsp; Sure, you might get hints at problem areas early on, but those are usually gross, easy-to-find-and-remedy problems usually contained within a single susbsystem.&amp;nbsp; It&amp;#39;s not until you have enough infrastructure in place for the system as a whole to start working as a unit that you start to see the larger-scale problems, and coincidentally it&amp;#39;s usually about the same time that you start delivering drops to your customer.&lt;/p&gt;
&lt;p&gt;Our system collected event data from Programmable Logic Computers (PLCs) on the factory floor, aggregated that data into relational SQL CE tables, and then generated meaningful reports from that data through a light-weight ASP.NET Web Server running on Windows CE&amp;nbsp; that we built (I&amp;#39;ll discuss more on that specific technology in a future article).&amp;nbsp; The basic unit of measure that we used to judge system performance was the number of messages coming from PLCs that would could handle while still serving up reports.&lt;/p&gt;
&lt;p&gt;The customer&amp;#39;s initial&amp;nbsp; requirement included the ability to handle around 5 events per second, and early tests and proof-of-concept demonstrations had us running as many as 60 events per second so we were confident that we were not just going to meet their requirements, but dazzle them with an order-of-magnitude-better performance.&amp;nbsp; Then as we approached the time for final delivery of the system and we started tying all of the multitude of pieces together we suddenly found the system struggling to even handle 2 or 3 events per second, and new calculations from the customer we indicating a desire to handle not just 5 but 10 events per second.&lt;/p&gt;
&lt;p&gt;My initial instinct based on the application&amp;#39;s behavior and experience was that Garbage Collection was the problem, but as I outlined &lt;a href="http://community.opennetcf.com/articles/cf/archive/2007/08/10/don-t-fear-the-garbage-collector.aspx" class="" target="_blank"&gt;in a previous article&lt;/a&gt; that turned out not to be the case.&amp;nbsp; After heavily instrumenting the code I determined that a large amount of our cycle execution time was being spent in data access (a cycle being the receipt of an event as an array of bytes, parsing that event &amp;nbsp;and then storing the results in a table) .&lt;/p&gt;
&lt;p&gt;Part of the parsing and storage involved looking up foreign key integers from lookup tables (the events come in with &amp;quot;denormalized&amp;quot; text data, so we have to look up the ID based on text) and after instrumenting the code to even finer granularity I found that even these simple reads were taking a &lt;i&gt;lot &lt;/i&gt;longer than one would expect.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Profiling Lookup Table Access Speed&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Since I knew that simple lookups were taking a long time (tens to hundreds of milliseconds) I knew immediately that we needed to try to decrease this, but how?&amp;nbsp; We needed the data from the lookup table to do subsequent inserts and/or updates.&amp;nbsp; The answer was to generate our own data caching mechanism at the table level.&lt;/p&gt;
&lt;p&gt;Most data entities in the solution have been abstracted to single class definitions and a search on the table was done through methods like GetCustomerByID or GetIDFromCustomerName.&amp;nbsp; We were doing a lot of the latter type - getting an ID based on other fields, but the caching technique we&amp;#39;re going to cover in this article works well for any of them.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s a lot easier to talk about performance gains if we can quantify the performance before the &amp;quot;fix&amp;quot; and again after the fix, so before we move on to the solution, let&amp;#39;s take a look at some post-mortem investigation data I gathered.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;I created a simple application that creates a SQL CE database with a single table (our simulated lookup table) and then puts just 2 rows into the table.&amp;nbsp; With only 2 rows we remove the possible effects of any table indexing, since a lookup is going to require two fetches at most.&lt;/p&gt;
&lt;p&gt;I then created very basic code that would get a row from the table based on the row identifier (so SELECT * FROM Table WHERE RowID = &lt;i&gt;N&lt;/i&gt;). &amp;nbsp;The architecture of our large solution was such that most data transactions created their own connection to the database, so I added code to my test application&amp;nbsp; that used the same behavior.&amp;nbsp; To smooth out the results, the application would create the connection, open it, run the SQL and then close the connection.&amp;nbsp;&amp;nbsp; It did this 100 times and output the average time it took to perform the operation.&amp;nbsp; The results from running the test on three separate test devices are below (the actual production device being the first in the list):&lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Device&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Processor&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Mean Execution (ms)*&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;OLDI SAM-L8&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;800MHz Geode x86&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;7.5 to 9.5&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;iCOP eBox 2300&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;200MHz Vortex86&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;47 to 52&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Dell Axim x51&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;416MUz Intel PXA270&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;38 to 62&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;*Ranges are given because we ran several iterations of the 100-run tests&lt;/p&gt;
&lt;p&gt;Intuition and experience (and other developers) told me that the first step in improving these numbers would be to reuse the connection instead of creating and opening it every time.&amp;nbsp; So I modified the test application to create a global connection and use it without closing for all of the queries.&amp;nbsp; The results for those tests are below.&amp;nbsp; Note that these numbers exclude the first run which creates and opens the connection, so these numbers reflect purely the time to get one row of data from a table containing only two rows of data.&lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Device&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Processor&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Mean Execution (ms)&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;OLDI SAM-L8&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;800MHz Geode x86&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;7.1 to 14.8&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;iCOP eBox 2300&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;200MHz Vortex86&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;51 to 52&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Dell Axim x51&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;416MUz Intel PXA270&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;43 to 61&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;Now if you go back and look at the two result tables you&amp;#39;ll probably be as surprised as I was (and yes, I double- and triple-checked these numbers).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Lesson 1:&lt;/b&gt; &lt;i&gt;There&amp;#39;s no performance benefit whatsoever to keeping the connection created and opened through the run of your application.&lt;/i&gt; &lt;/p&gt;
&lt;p&gt;Ok, so things aren&amp;#39;t quite what we expected, but I created a meaningful test that provided baseline numbers that I needed to improve.&amp;nbsp; The next step was to implement caching and then quantify the results to see if the improvement in performance warrants the extra time it takes to implement the caching itself.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Implementing a Data Cache&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;So what exactly is a data cache and how do we go about creating one? The concept (and really the implementation) is quite simple.&amp;nbsp; You start by creating a data type (could be a struct or a class) that describes a row of data. That entity can be a subset of the columns in a table if your lookup query typically only looks at a couple fields.&amp;nbsp; You then create a searchable collection to hold a series of these entities.&amp;nbsp; In my test application I used a Hashtable because it makes lookups by a key value very easy.&amp;nbsp; This collection of entities is the cache.&lt;/p&gt;
&lt;p&gt;Using the cache is simple.&amp;nbsp; When a table lookup is needed, instead of going right to the database you first look in the cache to see if the row is there.&amp;nbsp; If it is, you return the data from the cache.&amp;nbsp; If it&amp;#39;s not, you get it from the database, store it in the cache and then return the data.&amp;nbsp; In this way the cache grows as data is queried to spread out the load time over many operations.&amp;nbsp; Another mechanism would be to populate the cache with all of the lookup table rows on creation.&amp;nbsp;&amp;nbsp; This method would mean that all lookups, including the first will be as fast as possible, but you have to pay up front to fill it.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/200709/DataCache_1.PNG" title="Figure 1" style="width:631px;height:414px;" alt="Figure 1" height="414" width="631" /&gt;&lt;/p&gt;
&lt;p&gt;I added a cache to the test application and re-ran the tests.&amp;nbsp; The results follow.&amp;nbsp; Again these numbers omit the first run which was skewed high because we had 1 table lookup and 99 cached instead of 100 cache reads.&lt;/p&gt;
&lt;table cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Device&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Processor&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Mean Execution (ms)&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;OLDI SAM-L8&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;800MHz Geode x86&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;0.0193 to 0.0201&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;iCOP eBox 2300&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;200MHz Vortex86&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;0.1014 to 0.1164&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Dell Axim x51&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;416MUz Intel PXA270&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;0.0975 to 0.1437&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, again those numbers are correct - the decimal points are not in the wrong place.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Lesson 2:&lt;/b&gt; &lt;i&gt;Cache reads are two orders of magnitude faster than a database read.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Of course I expected the cache reads to be faster, but I wasn&amp;#39;t expecting this much of a gap.&amp;nbsp; In fact I have no explanation for why the difference is so large.&amp;nbsp; The database that the test application created was in RAM, not persistent storage, so both the database read and the cache read are coming from RAM.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;So what did we learn from this test?&amp;nbsp; First, that the &amp;quot;general knowledge&amp;quot; that reusing a connection is faster appears to be completely false and second that caching data has some seriously large performance advantages.&amp;nbsp; Of course you still have to weigh those advantages against the advantages of getting the data from the database.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Your cached data is not going to get updated when a table is updated, so it probably not a good idea for tables that have data that changes a lot.&amp;nbsp; The cache maintenance code gets more complex if you have code that deletes or updates the lookup table.&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t join or query your cached data with SQL.&amp;nbsp; If the data is not a typical lookup table and is often used in joins, then it&amp;#39;s probably not a good candidate for caching.&lt;/p&gt;
&lt;p&gt;The data cache takes up memory.&amp;nbsp; If you have a really large lookup table (say a lookup of every product a large retail store has on its shelves for example) then a cache might not be a good idea, though you could modify the cache maintenance code to hold maybe the last 100 or so rows read, so frequently queried rows would often be in the cache and fast to read.&lt;/p&gt;
&lt;p&gt;So is caching the answer to every database performance woe that might plague you in a project?&amp;nbsp; Obviously not, but it is an important tool that you can use to improve some areas of your application. It is simply another tool that you now have and it&amp;#39;s going to be up to you to recognize if and when it&amp;#39;s applicable to a problem you&amp;#39;re working on, but at least now you know it exists. And, as I was told many times by a cartoon as a kid, knowing is half the battle.&amp;nbsp; Go Joe!&lt;/p&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=20" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Data Access" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Data+Access/default.aspx" /><category term="Performance" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Performance/default.aspx" /></entry><entry><title>Developing Connected Smart Device Applications with SqlClient</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/09/20/developing-connected-smart-device-application-with-sqlclient.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/09/20/developing-connected-smart-device-application-with-sqlclient.aspx</id><published>2007-09-20T19:11:00Z</published><updated>2007-09-20T19:11:00Z</updated><content type="html">&lt;p&gt;Prashant Dhingra&lt;br /&gt;Microsoft Corporation&lt;br /&gt;September 2007&lt;/p&gt;
&lt;p&gt;&lt;a class="" title="Download the Source" href="http://www.opennetcf.com/downloads/download.aspx?s=SSMS_Device"&gt;&lt;img src="http://community.opennetcf.com/blogs/cf/CSharp.PNG" align="middle" border="0" alt="" /&gt;Download the Sample Code&lt;/a&gt;&lt;/a&gt;&lt;strong&gt;&amp;nbsp;&lt;br /&gt;&lt;/strong&gt;&lt;a class="" href="http://community.opennetcf.com/blogs/cf/200709/Developing%20Connected%20Smart%20Device%20Application%20with%20SqlClient.pdf" target="_blank"&gt;&lt;img height="30" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;Download the PDF&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Microsoft .NET SqlClient class provides a consistent set of APIs for both .NET Framework and .NET Compact Framework applications. SqlClient is a data provider for Microsoft SQL Server. SqlServerCe is a data provider for accessing Microsoft SQL Server Compact Edition database.&lt;/p&gt;
&lt;p&gt;The SqlClient namespace exists both in the full .NET Framework and in .NET Compact Framework. &amp;nbsp;Generally speaking there are three high-level ways of providing data access using the Microsoft data providers:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Using a .NET Framework-based SqlClient data provider to access data in a SQL Server on from a PC&lt;/li&gt;
&lt;li&gt;Using a .NET Compact Framework-based SqlClient data provider to access data in a SQL Server from a device.&lt;/li&gt;
&lt;li&gt;Using a .NET Compact Framework-based SqlServerCe provider to access data in a SQL Server Compact Edition file directly on a device.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Accessing a SQL Server database from a device application is very similar to accessing a SQL Server database from a desktop application (methods 1 and 2 above). &lt;a class="" title="_Toc167123189" name="_Toc167123189"&gt;&lt;/a&gt;&lt;a class="" title="_Toc166776804" name="_Toc166776804"&gt;&lt;/a&gt;This exercise will look at number 2 by demonstrating how you can query and update a backend SQL Server Database using a Compact Framework-based Smart Device application. &lt;/p&gt;
&lt;p&gt;In this exercise you will develop a .NET Compact Framework application using Visual Studio 2005. The application will allow you to see real time data stored in SQL Server 2005. Since the application is directly accessing and updating SQL Server, it does not require the use of SQL Server Compact Edition nor do you need to configure replication. It does require that the device have reliable connectivity with the backend server while working on this application. &lt;/p&gt;
&lt;p&gt;From Device you can connect to SQL Server using TCP/IP connection. You need to configure SQL Server to accept remote connections over TCP/IP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Enable Remote Connections&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First you need to allow remote connections access to your SQL Server 2005 instance.&amp;nbsp; To allow remote connections, follow the steps below.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click on Start | All Programs | Microsoft SQL Server 2005 | Configuration Tools | SQL Server Surface Area configuration.&lt;br /&gt;&lt;br /&gt;&lt;img style="WIDTH:655px;HEIGHT:594px;" height="594" src="http://community.opennetcf.com/blogs/cf/200709/ssms_1.png" width="655" alt="" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;On the surface area configuration dialog click on &amp;quot;Surface Area Configuration for Services and Connections&amp;quot; option.&lt;/li&gt;
&lt;li&gt;Click on Remote Connections in Database engine node.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Enable Remote connections by clicking on Local and remote connections.&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 2" style="WIDTH:670px;HEIGHT:517px;" height="517" alt="Figure 2" src="http://community.opennetcf.com/blogs/cf/200709/ssms_2.png" width="670" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Select sub option &amp;quot;Using both TCP/IP and name pipes&amp;quot;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Note: SQL Server 2005 Express Edition, &amp;nbsp;Evaluation Edition and Developer Edition SKUs allow local connection only. Enterprise, Standard and Workgroup Edition SKUs allow remote connections over TCP\IP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Configure Windows Firewall&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If your system has the Windows Firewall configured, it must be configured to allow the remote connection to communicate with the SQL Server executable. Follow the steps given below to ensure connectivity through the firewall.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Start the Control Panel on the computer running SQL Server.&lt;/li&gt;
&lt;li&gt;Double Click on Windows Firewall.&lt;/li&gt;
&lt;li&gt;Click on the Exceptions tab.&lt;/li&gt;
&lt;li&gt;Click on the Add Program button.&lt;/li&gt;
&lt;li&gt;Add the path of sqlsrvr.exe. By default the sqlsrvr.exe is installed at &amp;lt;Drive&amp;gt;\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 3" style="WIDTH:393px;HEIGHT:403px;" height="403" alt="Figure 3" src="http://community.opennetcf.com/blogs/cf/200709/ssms_3.png" width="393" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Click OK.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Develop a SQL Server Management Studio application for Smart Devices&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now that you have configured your SQL Server to allow remote connections we&amp;#39;ll walk through creating a simple SQL Server Management Studio-like application that will run on a Smart Device.&amp;nbsp; This application will allow you to run SQL statements against the remote SQL Server directly from a connected device.&lt;/p&gt;
&lt;p&gt;This example uses the AdventureWorksDW database to allow users to run ad-hoc queries against the database without having to be at a desktop computer.&amp;nbsp; You can alter the connection string in the code to target any other database, or alternatively you might extend the code to allow the user to enter the database name through the user interface. &lt;/p&gt;
&lt;p&gt;Follow these steps to create the Smart Device application: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a Smart Device project (Windows Mobile 5 or Windows Mobile 6) in Visual Studio. Start Visual Studio 2005. The example uses Windows Mobile 6.0 Professional Edition.&lt;/li&gt;
&lt;li&gt;Add a reference to System.Data.SqlClient namespace in the project. Right click on References and Select Add Reference option. In the Add Reference dialog box Select System.Data.SqlClient dll. &lt;/li&gt;
&lt;li&gt;Design the user interface for project as shown in figure. &lt;/li&gt;
&lt;li&gt;Use Toolbox to create a Tab control with 4 tabs - Objects, SQL, Result and Notes.&lt;/li&gt;
&lt;li&gt;Create a Tree node on Objects Tab to display SQL Server database objects. &lt;/li&gt;
&lt;li&gt;Create a Text box in SQL Tab to run queries.&lt;/li&gt;
&lt;li&gt;Create a DataGrid on Result tab to display result.&lt;/li&gt;
&lt;li&gt;Create a Text box on Notes Tab.&lt;/li&gt;
&lt;li&gt;Create a button to execute queries.&lt;/li&gt;
&lt;li&gt;Optionally create multiple buttons to store queries&lt;/li&gt;
&lt;li&gt;You can make a user interface similar to SQL Server Compact Edition Query Analyzer that connects to SQL Server instead of SQL Server Compact Edition database.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The code below demonstrates how to access the remote SQL server using the SqlClient provider objects and display the results in a DataGrid.&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.Collections.Generic;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.ComponentModel;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.Data;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.Drawing;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.Text;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.Windows.Forms;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;using&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; System.Data.SqlClient;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;namespace&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt; SSMS_Device&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;partial&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;class&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;SSMS&lt;/span&gt; : &lt;span style="COLOR:#2b91af;"&gt;Form&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;SqlConnection&lt;/span&gt; myConn;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;String&lt;/span&gt; connStr;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; SSMS()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; connStr =&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#a31515;"&gt;@&amp;quot;Server=&amp;#39;PDHINGRA&amp;#39;;Database=AdventureWorksDW; User Id=MyLogin; Password=MyPassword&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; button10_Click(&lt;span style="COLOR:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="COLOR:#2b91af;"&gt;EventArgs&lt;/span&gt; e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myConn = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;SqlConnection&lt;/span&gt;(connStr);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myConn.Open();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FillList();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;catch&lt;/span&gt; (&lt;span style="COLOR:#2b91af;"&gt;Exception&lt;/span&gt; ex)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Connection error: &amp;quot;&lt;/span&gt; + ex.ToString());&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;finally&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myConn.Close();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR:green;"&gt;// button click&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; FillList()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;//SqlDataReader myDataReader;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;SqlDataAdapter&lt;/span&gt; myAdapter = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;SqlDataAdapter&lt;/span&gt;(txtSQL.Text, myConn);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;DataSet&lt;/span&gt; myDataSet = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;DataSet&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myAdapter.Fill(myDataSet, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Result&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:green;"&gt;// dataGridView1.DataSource = myDataSet.DefaultViewManager;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataGrid1.DataSource = myDataSet.Tables[&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Result&amp;quot;&lt;/span&gt;].DefaultView;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; FillObject()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myConn = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;SqlConnection&lt;/span&gt;(connStr);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myConn.Open();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;SqlDataReader&lt;/span&gt; myDataReader;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;SqlCommand&lt;/span&gt; myCmd = myConn.CreateCommand();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myCmd.CommandText = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;SELECT TABLE_SCHEMA, TABLE_NAME&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+ &amp;quot;&amp;nbsp;FROM INFORMATION_SCHEMA.TABLES WHERE&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &amp;quot; TABLE_TYPE = &amp;#39;BASE TABLE&amp;#39;&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; treeView1.BeginUpdate();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; treeView1.Nodes.Clear();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; treeView1.Nodes.Add(&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;TreeNode&lt;/span&gt;(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Tables&amp;quot;&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;TreeNode&lt;/span&gt; childNode = treeView1.Nodes[0];&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; childCount = 0;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;myDataReader = myCmd.ExecuteReader();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;while&lt;/span&gt; (myDataReader.Read())&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; TableName = (myDataReader[0].ToString()) &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &lt;span style="COLOR:#a31515;"&gt;&amp;quot;.&amp;quot;&lt;/span&gt; + (myDataReader[1].ToString());&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; childNode.Nodes.Insert(childCount, &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;TreeNode&lt;/span&gt;(TableName));&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; childCount += 1;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myDataReader.Close();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; treeView1.Nodes.Add(&lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;TreeNode&lt;/span&gt;(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Views&amp;quot;&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;SqlCommand&lt;/span&gt; myCmdView = myConn.CreateCommand();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myCmdView.CommandText = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;SELECT TABLE_SCHEMA, &amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &amp;quot;TABLE_NAME FROM INFORMATION_SCHEMA.TABLES &amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+ &amp;quot;WHERE TABLE_TYPE = &amp;#39;VIEW&amp;#39;&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;TreeNode&lt;/span&gt; childNodeView = treeView1.Nodes[1];&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; childCountView = 0;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myDataReader = myCmdView.ExecuteReader();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;while&lt;/span&gt; (myDataReader.Read())&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; ViewName = (myDataReader[0].ToString()) &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + &lt;span style="COLOR:#a31515;"&gt;&amp;quot;.&amp;quot;&lt;/span&gt; + (myDataReader[1].ToString());&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; childNodeView.Nodes.Insert(childCount, &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;TreeNode&lt;/span&gt;(ViewName));&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; childCountView += 1;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myDataReader.Close();&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;treeView1.ExpandAll();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; treeView1.EndUpdate();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myConn.Close();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR:green;"&gt;// try&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;catch&lt;/span&gt; (&lt;span style="COLOR:#2b91af;"&gt;SqlException&lt;/span&gt; myexception)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR:#2b91af;"&gt;SqlError&lt;/span&gt; err &lt;span style="COLOR:blue;"&gt;in&lt;/span&gt; myexception.Errors)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(err.Message);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR:green;"&gt;// catch&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;private&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; SSMS_Load(&lt;span style="COLOR:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="COLOR:#2b91af;"&gt;EventArgs&lt;/span&gt; e)&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FillObject();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN-BOTTOM:0pt;"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE:10pt;FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Build and compile the application.&lt;/li&gt;
&lt;li&gt;Deploy the application to an emulator or a device. &lt;/li&gt;
&lt;li&gt;The application will start and create a connection to backend SQL Server. &lt;/li&gt;
&lt;li&gt;The application then fetches the table and view names from the INFORMATION_SCHEMA.TABLES view. &lt;/li&gt;
&lt;li&gt;The tables and views are then displayed in a TreeView as shown in the figure below.&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 4" style="WIDTH:358px;HEIGHT:556px;" height="556" alt="Figure 4" src="http://community.opennetcf.com/blogs/cf/200709/ssms_4.png" width="358" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Click on the SQL Tab and enter a SQL query such as that shown in the figure below.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Click on the Execute Button (&amp;quot;&amp;gt;&amp;quot;) to run your query.&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 5" style="WIDTH:358px;HEIGHT:556px;" height="556" alt="Figure 5" src="http://community.opennetcf.com/blogs/cf/200709/ssms_5.png" width="358" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;When the Execute B is clicked, the application creates a connection to the backend AdventureWorks database and exeutes the query. The result are then populated in the Results Tab as shown in figure below.&lt;/li&gt;
&lt;li&gt;Click on the Results Tab to see the result. &lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 6" style="WIDTH:358px;HEIGHT:556px;" height="556" alt="Figure 6" src="http://community.opennetcf.com/blogs/cf/200709/ssms_6.png" width="358" /&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;The code in the download doesn&amp;#39;t use the Notes tab, but you could add information to it such as the time required to execute the query, the number of rows affected, etc.&lt;/p&gt;
&lt;h3&gt;Difference between SqlClient provider in .NET Framework and .in NET Compact Framework&lt;/h3&gt;
&lt;p&gt;The System.Data.SqlClient provider is a collection of classes to access SQL Server 2005 databases. You can use the SqlClient provider in a Smart Device platform in the same way you use the SqlClient provider in a Desktop application, however there are few differences in the .NET Compact Framework version of the provider that are important to note.&amp;nbsp; For the .NET Compact &amp;nbsp;Framework&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The SqlClientPermission and SqlClientPermissionAttribute classes are not supported.&lt;/li&gt;
&lt;li&gt;Connection Pooling is not supported&lt;/li&gt;
&lt;li&gt;Transactions spanning to multiple databases are not supported&lt;/li&gt;
&lt;li&gt;Direct TCP/IP connections to a SQL Server instance are supported&lt;/li&gt;
&lt;li&gt;Windows authentication is supported, however you must specify the user id and password in the connection string.&lt;/li&gt;
&lt;li&gt;Encrypted connections to SQL Server instances are not supported. The connection will fail if computer running SQL Server has an SSL certificate installed&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;In this exercise you built a tool similar to SQL Server Management Studio to run on Mobile devices. You can use the tool to execute SQL queries from a mobile device directly against a backend SQL Server. This exercise also demonstrated how to build connected enterprise applications for mobile devices. &lt;/p&gt;
&lt;h3&gt;Building an Enterprise Solution - Connected vs Disconnected&lt;/h3&gt;
&lt;p&gt;This exercise has shown that it&amp;#39;s straightforward to create an enterprise application with a direct connection to a back-end SQL Server.&amp;nbsp; An alternative is to maintain a local SQL CE Compact Edition data store on the Smart Device itself and use the SqlServerCe provider for data access. &lt;/p&gt;
&lt;p&gt;The &lt;a class="" title="Amazon Link" href="http://www.amazon.com/Microsoft-SQL-Server-2005-Compact/dp/0672329220/ref=pd_bbs_sr_1/103-2446933-2055016?ie=UTF8&amp;amp;s=books&amp;amp;qid=1190322101&amp;amp;sr=8-1" target="_blank"&gt;SQL Server Compact Edition book (ISBN : 0672329220)&lt;/a&gt; has detailed exmples for building enterprise applications using both the System.Data.SqlClient and System.Data.SqlServerCe namespaces.&lt;/p&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=19" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="SQL Server" scheme="http://community.opennetcf.com/articles/cf/archive/tags/SQL+Server/default.aspx" /><category term="Data Access" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Data+Access/default.aspx" /></entry><entry><title>Debugging Without ActiveSync</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/08/31/debugging-without-activesync.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/08/31/debugging-without-activesync.aspx</id><published>2007-08-31T15:23:00Z</published><updated>2007-08-31T15:23:00Z</updated><content type="html">&lt;p&gt;Chris Tacke&lt;br /&gt;OpenNETCF Consulting&lt;br /&gt;March 2007&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a class="" href="http://community.opennetcf.com/blogs/cf/200708/downloads/CEDbgSetup.zip"&gt;Download CEDebgSetup source and binaries&lt;/a&gt;&lt;br /&gt;&lt;a class="" title="Download the PDF" href="http://community.opennetcf.com/blogs/cf/200708/Debugging%20without%20ActiveSync.pdf" target="_blank"&gt;&lt;img height="32" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;Download the PDF&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;If you&amp;#39;ve tried to debug a native or managed application with Microsoft Visual Studio 2005 on any device other than a Windows Mobile device, you&amp;#39;re likely very aware of how painful it can be to just get connected.&amp;nbsp; Typically it&amp;#39;s a process requiring the proper alignment of planets, holding your tongue just right and often a visit to Stonehenge.&lt;/p&gt;
&lt;p&gt;We hope that this short white paper&amp;nbsp; along with CeDbgSetup.exe will take a lot of the pain out of the process.&amp;nbsp; &lt;/p&gt;
&lt;h1&gt;Requirements and Assumptions&lt;/h1&gt;
&lt;p&gt;Before proceeding, make sure you have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Visual Studio 2005, Standard Edition or better with Service Pack 1 (SP1) installed. If you don&amp;#39;t have SP1, CeDbgSetup.exe will deploy the wrong CoreCon files for your environment and Studio will only laugh at you with a very unhelpful &amp;quot;Cannot Connect&amp;quot; message.&lt;/li&gt;
&lt;li&gt;CeDbgSetup.exe. This is a free, shared source tool that we&amp;#39;ve written to do a lot of the grunt work on the device for you. As usual it&amp;#39;s provided as-is and without warranty, but if you have a problem let us know. &lt;br /&gt;As of this writing CeDbgSetup.exe supports only ARMv4I and x86 devices. Sorry to you MIPS and SHx developers, but I don&amp;#39;t have a device with one of those processors, so I can&amp;#39;t build or test the tool for those architectures. If you have an SDK for one of them, let us know and we may be able to update the tool.&lt;/li&gt;
&lt;li&gt;As of this writing we&amp;#39;ve only verified that this works with Studio running on Windows XP. &lt;/li&gt;
&lt;li&gt;You probably should shut off or put an exception in firewalls and other security stuff that might interfere with the transport&lt;/li&gt;
&lt;li&gt;We&amp;#39;ve tested with the PC and the device running 802.11 connections, so yes, this work wireless on either or both sides&lt;/li&gt;
&lt;li&gt;You &lt;u&gt;don&amp;#39;t&lt;/u&gt; need ActiveSync. Need we say more?&lt;/li&gt;&lt;/ul&gt;
&lt;h1&gt;Configure the device&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;First make sure the device has a valid IP address. Record the IP for future use.&lt;br /&gt;Using a fixed IP, especially on networks where the DHCP lease is short and addresses change frequently. If the device IP address changes, this entire process must be done again.&lt;/li&gt;
&lt;li&gt;Deploy and Run &lt;b&gt;CeDbgSetup.exe&lt;/b&gt; on the device. This application is provided for free from OpenNETCF Consulting. If your device has a mechanism to persist the file and auto-launch it on boot, then we recommend that you do so to make things simple.&lt;br /&gt;When successfully run, shortcuts will be added to the device desktop. In normal operation you should not actually need to use these shortcuts.&lt;/li&gt;&lt;/ol&gt;
&lt;h1&gt;Configure the PC&lt;/h1&gt;
&lt;p&gt;1. Verify you can ping the device the ensure that there is a solid communication channel.&lt;/p&gt;
&lt;h1&gt;Configure Visual Studio&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;Enable the Device toolbar by right-clicking on Studio&amp;#39;s toolbar and checking ‘Device&amp;#39;&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 1" style="WIDTH:150px;HEIGHT:408px;" height="408" alt="Figure 1" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging1.PNG" width="150" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Select your target device. In this example we&amp;#39;ll choose the iCOP eBox 2300, which is running CE 6.0. You&amp;#39;ll see that I&amp;#39;ve got several other devices to choose from.&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 2" style="WIDTH:343px;HEIGHT:215px;" height="215" alt="Figure 2" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging2.PNG" width="343" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Open the Devices option window by either clicking the ‘Device Options&amp;#39; button on the Device toolbar or using the following menu path Tools-&amp;gt;Options-&amp;gt;Device Tools-&amp;gt;Options.&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 3" style="WIDTH:520px;HEIGHT:358px;" height="358" alt="Figure 3" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging3.PNG" width="520" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Select your platform from the &amp;quot;Show devices for Platform&amp;quot; dropdown. &lt;br /&gt;&lt;/li&gt;
&lt;li&gt;In the &amp;quot;Devices&amp;quot; list, select your target device. At thins point it may be useful to rename the device. You can also &amp;quot;clone&amp;quot; any device by clicking &amp;quot;Save As&amp;quot; which can be helpful if you want to have different transports or IP addresses for the same type of target device.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Select your device in the &amp;quot;Devices&amp;quot; list and click &amp;quot;Properties&amp;quot;&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 4" style="WIDTH:442px;HEIGHT:314px;" height="314" alt="Figure 4" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging4.PNG" width="442" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Click on the &amp;quot;Configure&amp;quot; button&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 5" style="WIDTH:436px;HEIGHT:229px;" height="229" alt="Figure 5" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging5.PNG" width="436" /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Select the &amp;quot;Use specific IP address&amp;quot; radio button and enter device&amp;#39;s IP address you recorded way back at the start of this process.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Click the &amp;quot;OK&amp;quot; button on all 3 dialogs to bring you back to Studio.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Click the &amp;quot;Connect to Device&amp;quot; button on the Device toolbar&lt;br /&gt;&lt;br /&gt;&lt;img title="Figure 6" style="WIDTH:344px;HEIGHT:60px;" height="60" alt="Figure 6" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging6.PNG" width="344" /&gt;&lt;br /&gt;&lt;br /&gt;You should see the following:&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;img title="Figure 7" style="WIDTH:405px;HEIGHT:208px;" height="208" alt="Figure 7" src="http://community.opennetcf.com/blogs/cf/200708/figures/Debugging7.PNG" width="405" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At this point Visual Studio can communicate with the device and you&amp;#39;re ready to develop.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=8" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Debugging" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Debugging/default.aspx" /><category term="ActiveSync" scheme="http://community.opennetcf.com/articles/cf/archive/tags/ActiveSync/default.aspx" /></entry><entry><title>Image Manipulation in Windows Mobile 5.0</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/08/30/image-manipulation-in-windows-mobile-5.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/08/30/image-manipulation-in-windows-mobile-5.aspx</id><published>2007-08-30T20:29:00Z</published><updated>2007-08-30T20:29:00Z</updated><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Rob Miles&lt;br /&gt;Department of Computer Science, University of Hull&lt;br /&gt;August 2007&lt;/p&gt;
&lt;p&gt;&lt;a class="" title="Sample 1" href="http://community.opennetcf.com/articles/downloads/200708/WM5ImageProc1.zip"&gt;Download Sample Image Capture&lt;/a&gt;&lt;br /&gt;&lt;a class="" title="Sample 2" href="http://community.opennetcf.com/articles/downloads/200708/WM5ImageProc2.zip"&gt;Download Full Image Processing Game&lt;/a&gt;&lt;br /&gt;&lt;a class="" href="http://community.opennetcf.com/blogs/cf/200708/WM5ImageManipulation.pdf"&gt;&lt;img height="30" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;Download the PDF&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Introduction&lt;/h4&gt;
&lt;p&gt;Windows Mobile 5.0 offers the prospect of games based on images which the player captures with the onboard camera. In this article you will discover how to capture such images and prepare them for use as sprites and backgrounds in a game.&lt;/p&gt;
&lt;h4&gt;What You Will Need to Get Started&lt;/h4&gt;
&lt;p&gt;You will need Visual Studio .NET 2005. You will also need to acquire the Windows Mobile 5.0 SDK for the device that you are targeting. This is a free download.&lt;/p&gt;
&lt;p&gt;You don&amp;#39;t actually need a phone handset or mobile device because you will be using techniques that make it possible to do all the work on the emulators provided by Microsoft Visual Studio® .NET 2005. However, the emulators do not support the camera behavior, although you can use the image loading dialog.&lt;/p&gt;
&lt;p&gt;If you have a device, it will make things much more interesting. Only the most recent Windows Mobile 5 devices have Compact Framework Version 2.0 built in, but this will be installed automatically as required when the program is downloaded into the device.&lt;/p&gt;
&lt;p&gt;If you want to download the programs into a real device you will also need Active Sync version 4.1. The programs have been tested on an SPV C500 and an Imate Jasjar.&lt;/p&gt;
&lt;h4&gt;The Camera in a Mobile Device&lt;/h4&gt;
&lt;p&gt;Whilst Smartphones have always been supplied with cameras, and many Pocket PC devices now sport them, it is only with Windows Mobile 5.0 that programmers are able to use them easily. In previous devices the camera has been controlled by software which was specifically written by the hardware manufacturers. This software did not provide a way in which programmers writing in managed code could easily interact with the camera to initiate the taking of pictures. That has changed in the latest version of Windows Mobile, it is now possible for a program to initiate the taking of photographs by the device owner.&lt;/p&gt;
&lt;p&gt;However, it is important to understand just what level of use you can make of the camera. There is no direct camera control from a C# program, in that you cannot order the camera to take a picture. Instead your program displays a camera capture dialog form. When the user has taken a picture control is returned to your program.&lt;/p&gt;
&lt;p&gt;If you want direct control of the camera device itself this can be achieved by use of the DirectShow interface which is also supported by Windows Mobile 5.0. However, for the purpose of simple games, allowing the user to take a photograph is sufficient.&lt;/p&gt;
&lt;h4&gt;Getting Started with Visual Studio 2005 and Mobile Devices&lt;/h4&gt;
&lt;p&gt;The kind of project that you need is a Visual Studio 2005 .NET Compact Framework Version 2.0 forms application.&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 1" style="WIDTH:209px;HEIGHT:257px;" height="257" alt="Figure 1" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation1.gif" width="209" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 1. Creating the new project&lt;/p&gt;
&lt;p&gt;Note that you only get the Windows Mobile 5.0 projects once you have installed the appropriate software development kits (SDK). The examples that are going to be created will target the Windows Mobile 5.0 Smartphone with a QVGA display. All the code can be used on other platforms with only minimal changes.&lt;/p&gt;
&lt;p&gt;Once you have created a new project, the next thing to consider is the form factor of the target device. At present Smartphone devices are available with two screen resolutions, the 176x220 of the original and 320x240 of more recent devices. The higher resolution is often referred to as QVGA because the screen is quarter the size of a 640x40 VGA screen. You can select the screen resolution by using the FormFactor property of the form:&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 2" style="WIDTH:284px;HEIGHT:221px;" height="221" alt="Figure 2" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation2.gif" width="284" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 2. Selecting the FormFactor&lt;/p&gt;
&lt;p&gt;Note that as a general rule you should make sure that your program will work with either size screen. However this feature is useful for allowing you to match your program with a particular sized device. I am going to be using the camera on device with QVGA resolution, so I have selected this option. You should select the option which matches your target device.&lt;/p&gt;
&lt;h4&gt;The Microsoft.WindowsMobile.Forms Resource&lt;/h4&gt;
&lt;p&gt;The CameraCaptureDialog is actually supplied in the Microsoft.WindowsMobile.Forms library. This is part of the Windows Mobile 5.0 SDK, but is not automatically added as a reference when a project is built. To add the library, right click on the References item in the Solution Explorer, select Add Reference from the menu which appears and then add the library:&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 3" style="WIDTH:209px;HEIGHT:257px;" height="257" alt="Figure 3" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation1.gif" width="209" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 3. The WindowsMobile Forms library&lt;/p&gt;
&lt;p&gt;Now our program can create and use all the items in this library, including the CameraCaptureDialog.&lt;/p&gt;
&lt;h4&gt;Using the CameraCaptureDialog Form&lt;/h4&gt;
&lt;p&gt;A camera capture dialog is created like any other dialog box, and also shown in the same way. The code to take a picture is as follows:&lt;/p&gt;
&lt;p&gt;CameraCaptureDialog&lt;b&gt; cameraDialog = &lt;/b&gt;new&lt;b&gt; &lt;/b&gt;CameraCaptureDialog&lt;b&gt;();&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;if&lt;b&gt; ( cameraDialog.ShowDialog()==&lt;/b&gt;DialogResult.OK ) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // if we get here the picture has been taken correctly&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // the FileName property gives the name of the image file&lt;br /&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Note that the dialog does not return an image; instead it functions like a file dialog, in that it returns the name of the file where the image has been stored. If you want to use the image in your program you must then load the image from the file. The camera capture dialog has a cancel option, so your program must always allow for the action being cancelled.&lt;/p&gt;
&lt;p&gt;As with other windows forms, it is important to restore the original form once the picture has been taken. The method below will use the CameraCaptureDialog to take a picture and return the name of the picture file if this succeeds. It is called from within an existing form, and will return the display to that form when it finishes.&lt;/p&gt;
&lt;p&gt;private string takePicture()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string result = null;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CameraCaptureDialog cameraDialog = new CameraCaptureDialog();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cameraDialog.Mode = CameraCaptureMode.Still;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cameraDialog.StillQuality = CameraCaptureStillQuality.High;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cameraDialog.Resolution = new Size(640, 480);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( cameraDialog.ShowDialog()==DialogResult.OK ) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result = cameraDialog.FileName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Show();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cameraDialog.Dispose();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Note that it the code also sets properties of the dialog to select a high quality still image at a resolution of 640x480 (although the user can override these when the picture is taken). When the method runs the camera capture dialog on the Smartphone is displayed:&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 4" style="WIDTH:240px;HEIGHT:320px;" height="320" alt="Figure 4" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation4.gif" width="240" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 4. A Camera Capture Dialog&lt;/p&gt;
&lt;p&gt;Note that the precise appearance of this dialog, and the options which are available for the camera, will vary from one Windows Mobile device to another.&lt;/p&gt;
&lt;h4&gt;Using the SelectPictureDialog Form&lt;/h4&gt;
&lt;p&gt;Sometimes the user may wish to select an existing picture from a file instead. Windows Mobile 5 provides an additional dialog which can be used to select a picture. It is used in exactly the same way as the camera dialog.&lt;/p&gt;
&lt;p&gt;SelectPictureDialog&lt;b&gt; selectDialogue = &lt;/b&gt;new&lt;b&gt; &lt;/b&gt;SelectPictureDialog&lt;b&gt;();&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;if&lt;b&gt; (selectDialogue.ShowDialog() == &lt;/b&gt;DialogResult.OK)&lt;br /&gt;&lt;b&gt;{&lt;br /&gt;&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // if we get here the picture file has been selected&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // the FileName property gives the name of the image file&lt;br /&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 5" style="WIDTH:240px;HEIGHT:320px;" height="320" alt="Figure 5" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation5.gif" width="240" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 5. A Select Picture Dialog&lt;/p&gt;
&lt;p&gt;The SelectPictureDialog also contains the option of taking a picture with the camera as well. If the user does this, the name of the file containing the picture that was taken is returned.&lt;/p&gt;
&lt;h4&gt;Sample Image Application&lt;/h4&gt;
&lt;p&gt;The sample application allows you to load an image or take a picture using the camera. The image which is loaded is displayed in a picture box.&lt;/p&gt;
&lt;h4&gt;Image Processing to create Sprites&lt;/h4&gt;
&lt;p&gt;Capturing full sized pictures is a start, but if they are to be used in games they need to be converted into images which can be used as the basis of game sprites. This means that they will probably need to be cropped down, so that only part of the picture is to be used. As a plain edged sprite will not be very interesting, it would also be useful to be able to create sprites with a softer edge, and with more interesting shapes. &lt;/p&gt;
&lt;p&gt;This can be achieved by the use of a mask image which is combined with part of the captured image to produce shapes. &lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 6" style="WIDTH:355px;HEIGHT:353px;" height="353" alt="Figure 6" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation6.gif" width="355" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 6. A Round Mask&lt;/p&gt;
&lt;p&gt;The figure shows a mask which can be used to create a round sprite. The purple background color will be set as the transparent color when the sprite is drawn. The other colors on the mask will be added to the existing pixels so that the sprite appears to get lighter towards the edge. The center of the circle is black, so that part will have no effect on the image. Our clipping code must resize the image and add the mask to get the desired effect.&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 7" style="WIDTH:144px;HEIGHT:150px;" height="150" alt="Figure 7" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation7.gif" width="144" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 7. Applying the Mask&lt;/p&gt;
&lt;p&gt;Figure 7 shows the mask after it has been applied to part of a picture. The sprite that is produced has been resized to an appropriate resolution and then drawn on a black background.&lt;/p&gt;
&lt;h5&gt;Working with Bitmaps&lt;/h5&gt;
&lt;p&gt;It is comparatively easy to get hold of the color of a particular pixel in an image. The Bitmap class provides a method called GetPixel which returns the color at a particular pixel position in the bitmap:&lt;/p&gt;
&lt;p&gt;Color pixelCol = myBitmap.GetPixel(0,0);&lt;/p&gt;
&lt;p&gt;This would obtain the color of the pixel in the top left hand corner of the bitmap and set the variable pixelCol to that value. There is a corresponding SetPixel method which can be used to set the color of a pixel:&lt;/p&gt;
&lt;p&gt;myBitmap.SetPixel(0,0,Color.Red);&lt;/p&gt;
&lt;p&gt;This would set the color of the pixel in the top left hand corner of the bitmap to red. &lt;/p&gt;
&lt;p&gt;The sprite generation program must combine pixels in the mask with those in the source image. Pixels in the source image which are in the same position as transparent ones in the mask must be set to the transparent color, otherwise the mask pixel color values are added to the source ones:&lt;/p&gt;
&lt;p&gt;Color maskColor = mask.GetPixel((int&lt;b&gt;)maskX, (&lt;/b&gt;int&lt;b&gt;)maskY);&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;if&lt;b&gt; (maskColor.Equals(transparentColor))&lt;br /&gt;&lt;/b&gt;&lt;b&gt;{&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; source.SetPixel(sourceX, sourceY, transparentColor);&lt;br /&gt;&lt;/b&gt;&lt;b&gt;}&lt;br /&gt;&lt;/b&gt;else&lt;b&gt; &lt;br /&gt;&lt;/b&gt;&lt;b&gt;{&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;if&lt;b&gt; (!maskColor.Equals(Color.Black) ) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;&lt;b&gt;{&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Color sourceColor = source.GetPixel(sourceX, sourceY);&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;int&lt;b&gt; red = masterColor.R + maskColor.R;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;if&lt;b&gt; (red &amp;gt; 255) red = 255;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;int&lt;b&gt; green = masterColor.G + maskColor.G;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;if&lt;b&gt; (green &amp;gt; 255) green = 255;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;int&lt;b&gt; blue = masterColor.B + maskColor.B;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;if&lt;b&gt; (blue &amp;gt; 255) blue = 255;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; source.SetPixel(sourceX, sourceY,&amp;nbsp;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Color.FromArgb( red, green, blue));&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/b&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This code fetches a pixel from the mask at location maskX, maskY. If the mask pixel is the same color as the transparent color the source image pixel at sourceX,sourceY is set to transparent. If the pixel is not the transparent color the program adds the color of the pixel in the mask is added to the color of the source.&lt;/p&gt;
&lt;p&gt;Note that the color value is limited to the range 0-255, to stop strange effects if the value wraps around. If the above statements are performed on each pixel on the image, and the X and Y values are updated appropriately, this will perform the image processing that is required. Unfortunately it takes a long time to do this. On a standard Smartphone it can take a few minutes to process even a small image.&lt;/p&gt;
&lt;h5&gt;Speeding up Bitmap Access&lt;/h5&gt;
&lt;p&gt;The problem is that the GetPixel and SetPixel methods are very slow. The managed C# is trying to access the low level bitmap information and this takes time. To improve the speed the program must access this low level information directly. It turns out that this is quite easy. The Bitmap class provides a method called LockBits which will provide a pointer to the bitmap image data in memory. It also locks this data in position, so that it will not be moved around by the system.&lt;/p&gt;
&lt;p&gt;BitmapData bitmapBase = myBitmap.LockBits(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bounds,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // bounding rectangle on the bitmap&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ImageLockMode.ReadWrite,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // mode of the access&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PixelFormat.Format24bppRgb) ;&amp;nbsp;&amp;nbsp; // required format - 8 bits per color&lt;/p&gt;
&lt;p&gt;The actual image data is presented as a sequence of pixel values for each row of the image in turn. In other words an image which is 60 pixels wide and 40 pixels high would have 180 bytes of data for the top row, followed by 180 bytes for the next, and so on. &lt;/p&gt;
&lt;p&gt;The BitmapData provides us with the base of the screen, as a pointer to bytes:&lt;/p&gt;
&lt;p&gt;private Byte* bitmapBaseByte;&lt;br /&gt;bitmapBaseByte = (Byte*) bitmapBase.Scan0.ToPointer();&lt;/p&gt;
&lt;p&gt;The pointer variable bitmapBaseByte now points at the beginning of the raw data for our image. In other words, since first byte of a pixel is the blue component for that pixel, the code:&lt;/p&gt;
&lt;p&gt;*bitmapBaseByte = 0xFF;&lt;/p&gt;
&lt;p&gt;- would se the blue component of the top left hand pixel on the screen to maximum.&lt;/p&gt;
&lt;p&gt;The actual pixel data is placed in memory as three consecutive 8 bit values for blue, green and red respectively. The best way to manipulate this in C# is to use a structure: &lt;/p&gt;
&lt;p&gt;public struct PixelData&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public byte blue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public byte green;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public byte red;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;By careful use of casting the program can pull out the color components in each pixel:&lt;/p&gt;
&lt;p&gt;PixelData * currentPixel = *((PixelData*)( bitmapBaseByte));&lt;br /&gt;currentPixel-&amp;gt;green = 0;&lt;/p&gt;
&lt;p&gt;This would set the green component of the top left hand pixel to minimum.&lt;/p&gt;
&lt;p&gt;The program can move down the image to the next pixel by incrementing the pointer. To move to the next row of the image the pointer must be increased by the size of the row. There is a slight complication in that the number of bytes in each row is must always be a multiple of four when the bitmap data is mapped into memory. If this is not the case then the end of the row is padded out with &amp;quot;blank&amp;quot; bytes up to the nearest four byte boundary.&lt;/p&gt;
&lt;p&gt;In the case of a row which contains 50 pixels the actual number of bytes in each row would be 152, i.e. 50 pixels multiplied by 3 bytes per pixel gives 150. This is then lifted up to 152, that being the nearest value to 150 which is divisible by 4. This makes the calculation of the width of each row slightly more complicated:&lt;/p&gt;
&lt;p&gt;byteWidth = pixelWidth * 3;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;if&lt;/b&gt; (byteWidth % 4 != 0)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; byteWidth += (4 - (byteWidth % 4));&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;The pixelWidth value is multiplied by three (blue, green and red bytes) to get the byteWidth value. If this width is not divisible by four it is adjusted upwards by the appropriate amount. &lt;/p&gt;
&lt;p&gt;Once the raw data manipulation is complete the bitmap must be unlocked so that it can be returned to normal use:&lt;/p&gt;
&lt;p&gt;myBitmap.UnlockBits(bitmapBase);&lt;/p&gt;
&lt;h5&gt;Unsafe Code&lt;/h5&gt;
&lt;p&gt;Note that this means that our C# code is no longer safe, in that we are following pointers directly into memory, which bypasses all the usual safety checks performed in managed code. This means that the class which contains methods which do this must be declared as unsafe:&lt;/p&gt;
&lt;p&gt;public unsafe class ProcessBitmaps {&lt;/p&gt;
&lt;p&gt;For this to build correctly, the project must be modified to allow unsafe code to be compiled. This setting can be found on the Build tab in the Project Properties:&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 8" style="WIDTH:273px;HEIGHT:250px;" height="250" alt="Figure 8" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation8.gif" width="273" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 8. Allowing unsafe code in the project&lt;/p&gt;
&lt;p&gt;Figure 8 shows how this option is selected. If the program goes wrong, for example it tries to access a byte outside the range of the bitmap, it will not actually crash the host device, but it will fail without any kind of error report or exception being thrown.&lt;/p&gt;
&lt;h5&gt;&lt;a class="" title="_Moving_through_the_Bitmaps" name="_Moving_through_the_Bitmaps"&gt;&lt;/a&gt;Moving through the Bitmaps&lt;/h5&gt;
&lt;p&gt;When the sprite is being built the program must move through the source bitmap and combine the pixels in it with pixels in the mask bitmap. However, the bitmaps will not necessarily be the same shape and size. This means that the program must map the pixels from one bitmap into the matching ones in the other. This can be achieved by making the step through the mask bitmap the same relative size as the step through the image bitmap:&lt;/p&gt;
&lt;p&gt;float maskXStep = &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (float)maskBitmap.Width / (float) sourceRectangle.Width;&lt;/p&gt;
&lt;p&gt;float maskYStep = &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (float)maskBitmap.Height / (float) sourceRectangle.Height;&lt;/p&gt;
&lt;p&gt;float maskX = 0;&lt;br /&gt;float maskY = 0;&lt;/p&gt;
&lt;p&gt;The maskBitmap is the Bitmap containing the mask image. The variable sourceRectangle is a rectangle which describes the region of the source rectangle which is to be masked. The user selects this during the edit process. These two floating point steps are then used to update the position in the mask bitmap as each pixel in the source is processed. The step value corresponds to the movement of a single pixel in the given direction.&lt;/p&gt;
&lt;p&gt;for (int y = sourceRectangle.Top; y &amp;lt; sourceRectangle.Bottom; y++)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel = (PixelData*)(sourcepBase + y * sourceWidth +&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sourceRectangle.Left * sizeof(PixelData));&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mPixel = (PixelData*)(maskpBase + (int)maskY * maskWidth);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int x = sourceRectangle.Left; x &amp;lt; sourceRectangle.Right; x++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (mPixel-&amp;gt;red == transparentPixel.red &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mPixel-&amp;gt;green == transparentPixel.green &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mPixel-&amp;gt;blue == transparentPixel.blue)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // if the mask pixel color is the trasparent mask,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // overwrite the image pixel with our transparent colour&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;red = transparentPixel.red;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;blue = transparentPixel.blue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;green = transparentPixel.green;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // add the mask colour onto the image colour&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = mPixel-&amp;gt;red + pPixel-&amp;gt;red;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (value &amp;gt; 255) value = 255;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;red = (byte)value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = mPixel-&amp;gt;green + pPixel-&amp;gt;green;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (value &amp;gt; 255) value = 255;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;green = (byte)value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = mPixel-&amp;gt;blue + pPixel-&amp;gt;blue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (value &amp;gt; 255) value = 255;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;blue = (byte)value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int oldMaskX = (int)maskX;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maskX += maskXStep;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int dist = ((int)maskX) - oldMaskX;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mPixel += dist;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; maskX = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; maskY += maskYStep;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;The code above performs the masking process. The pixels are taken from a rectangle in the source image and combined with the appropriate ones in the mask image. If the source pixel corresponds with one which is set to the transparent color in the mask, the source pixel is set to transparent as well.&lt;/p&gt;
&lt;h4&gt;Controlling the Edit Process&lt;/h4&gt;
&lt;p&gt;The idea behind the program is that the user will take a picture with the camera and then select it for use as a sprite in the game. To do this they will have to move a cursor around the screen and also change the size of the cursor to fit the required region. &lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 9" style="WIDTH:262px;HEIGHT:377px;" height="377" alt="Figure 9" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation9.gif" width="262" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 9. Selecting the part of the image to clip&lt;/p&gt;
&lt;p&gt;The cursor can be made to operate in two modes, either moving over the screen or changing in size. The two modes are toggled by pressing in on the joystick. When the required part of the image has been selected the use presses the Done menu key to complete the image processing and create the sprite itself. The menu is used to select the cursor mode and also to allow the user to choose between a range of differently shaped masks for the mask cursor.&lt;/p&gt;
&lt;h5&gt;Managing the Cursor Bitmap&lt;/h5&gt;
&lt;p&gt;The first version of the program was written so that the actual image processing was performed during the image selection, in other words the mask was applied in real time so that the user was able to see the exact result of the crop action. Unfortunately, the processor in the Smartphone is not sufficiently powerful to do this and provide an acceptable user interface, so instead the mask was converted into a cursor image which is overlaid on the background.&lt;/p&gt;
&lt;p&gt;This image is obtained by converting all the black portion of the mask image into a transparent color, and then drawing the result on top of the background. A method, MakeBlackTransparent, was created which performs this simple image processing task. &lt;/p&gt;
&lt;p&gt;When the user selects a new mask another image is created which is used in this way. &lt;/p&gt;
&lt;h4&gt;Saving Bitmap data into image files&lt;/h4&gt;
&lt;p&gt;Windows Mobile 5 provides a very simple mechanism for saving bitmaps into files in a variety of image formats. The Image class provides a Save method which is supplied with the path to the file to be created and the image format:&lt;/p&gt;
&lt;p&gt;myBitmap.Save(@&amp;quot;\My Documents\My Pictures\Bitmap.bmp&amp;quot;, ImageFormat.Bmp);&lt;/p&gt;
&lt;p&gt;This would save the image in myBitmap into a file Bitmap.bmp with in the windows bitmap format. The ImageFormat enumerated type also lets you specify GIF, JPEG and PNG formats for the save operation. The path above causes the picture to be saved in the My Pictures subdirectory of the My Documents folder. &lt;/p&gt;
&lt;h4&gt;Creating the Background&lt;/h4&gt;
&lt;p&gt;The program can now produce interestingly shaped sprites which can then be used in a game. However, we also need a background for the sprites to move over. This can also be based on an image which was taken with a built in camera, but the image processing will be quite different.&lt;/p&gt;
&lt;p&gt;Rather than crop portions out of an image we will instead be performing image processing on the picture to make it more appropriate as a background. To do this the user may want to make the image brighter or darker, apply a color tint or add noise or other effects. The fundamental behavior of the code will be very similar, in that it will involve manipulating the colors in image data, but the action will be quite different:&lt;/p&gt;
&lt;p&gt;&lt;img title="Figure 10" style="WIDTH:240px;HEIGHT:320px;" height="320" alt="Figure 10" src="http://community.opennetcf.com/articles/figures/200708/WM5ImageManipulation10.gif" width="240" border="1" /&gt;&lt;/p&gt;
&lt;p&gt;Figure 10. An Image Processed Keyboard&lt;/p&gt;
&lt;p&gt;The above image shows a fairly boring picture of a keyboard which has been given the &amp;quot;wild&amp;quot; color process, had some noise added and then been increased in brightness to make an interesting background.&lt;/p&gt;
&lt;h5&gt;Color Manipulation&lt;/h5&gt;
&lt;p&gt;When performing image processing only the source image is required. There is no masking involved. The color manipulation can be performed by simply adding an adjustment value to each of the red, green and blue components of a pixel. The best way to do this is to make a single method which accepts the change values for each of the components. This single method can then be used tint an image or change the brightness simply by passing different data values in. The actual processing is quite simple, but the program must make sure that the color values do not go beyond the allowed 8 bit values:&lt;/p&gt;
&lt;p&gt;PixelData* pPixel;&lt;/p&gt;
&lt;p&gt;for (int y = 0; y &amp;lt; source.Height; y++)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel = (PixelData*)(sourcepBase + y * sourceWidth);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int x = 0; x &amp;lt; source.Width; x++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int redVal = pPixel-&amp;gt;red + redChange;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( redVal &amp;lt;0 ) redVal = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( redVal &amp;gt; 255) redVal = 255;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;red = (byte)redVal;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int greenVal = pPixel-&amp;gt;green + greenChange;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( greenVal &amp;lt;0 ) greenVal = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( greenVal &amp;gt; 255) greenVal = 255;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;green = (byte)greenVal;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int blueVal = pPixel-&amp;gt;blue + blueChange;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (blueVal &amp;lt; 0) blueVal = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (blueVal &amp;gt; 255) blueVal = 255;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;blue = (byte)blueVal;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;This code applies each of the change values, which can be either positive or negative, to perform the tinting action.&lt;/p&gt;
&lt;h5&gt;Image Processing&lt;/h5&gt;
&lt;p&gt;Most image processing programs provide a range of effects which can be used to make a picture more interesting. These include actions such as adding drawing effects and adding noise or remapping the color palette. We are going to use a couple of simple filters which will provide the user with some scope to make the background more artistic. These filters will operate only on single pixels, for effects such as blurring or lens distortion the code gets more complex as values must be transferred from one pixel to another.&lt;/p&gt;
&lt;h4&gt;The Wild Color Filter&lt;/h4&gt;
&lt;p&gt;One way to get a &amp;quot;wild&amp;quot; color effect is to add a random offset to the components in the color of a pixel. This will shift the color balance in potentially interesting ways. In this case the program does not limit the maximum values of the components, but instead allows them to wrap around the limits to get more interesting effects:&lt;/p&gt;
&lt;p&gt;int redVal = (pPixel-&amp;gt;red + redChange) % 256;&lt;br /&gt;pPixel-&amp;gt;red = (byte)redVal;&lt;br /&gt;int greenVal = (pPixel-&amp;gt;green + greenChange) % 256;&lt;br /&gt;pPixel-&amp;gt;green = (byte)greenVal;&lt;br /&gt;int blueVal = (pPixel-&amp;gt;blue + blueChange) % 256;&lt;br /&gt;pPixel-&amp;gt;blue = (byte)blueVal;&lt;/p&gt;
&lt;p&gt;In the code above the values of redChange, greenChange and blueChange are picked at random for the entire pass through the image. This very simple technique seems to result in genuinely interesting and often very artistic looking changes to the image. By using a fixed seed for the random number generator it is possible to make a given set of changes reproducible each time the program is used.&lt;/p&gt;
&lt;h4&gt;The Noise Filter&lt;/h4&gt;
&lt;p&gt;The noise filter randomly replaces pixels in the image with ones which have colors which have been randomly chosen. The amount of noise which is added can be controlled by the range of random numbers which trigger the swap action. A figure of 5% noise seems to give appropriate levels of noise:&lt;/p&gt;
&lt;p&gt;for (int y = 0; y &amp;lt; source.Height; y++)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel = (PixelData*)(sourcepBase + y * sourceWidth);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int x = 0; x &amp;lt; source.Width; x++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (rnd.Next(100) &amp;lt; 5)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;red = (byte)rnd.Next(255);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;green = (byte)rnd.Next(255);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel-&amp;gt;blue = (byte)rnd.Next(255);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pPixel++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;h4&gt;Selecting Image Processing Actions&lt;/h4&gt;
&lt;p&gt;Each of the image effects is selected from a given menu option. However, if the user wants to repeat a given action a number of times this would become tedious. The program has therefore been constructed so that it tracks the most recently used image processing option and then repeats this when the joystick is pushed in. This memory is managed in terms of a delegate instance which is set to point to the most recently used image processing method.&lt;/p&gt;
&lt;p&gt;delegate void imageProcessItem () ;&lt;/p&gt;
&lt;p&gt;The delegate imageProcessItem can be used to create delegate instances which refer to methods which are void and accept no parameters. The class contains a delegate which keeps track of the most recently used image processing method:&lt;/p&gt;
&lt;p&gt;private imageProcessItem doAddNoiseProcessItem = null;&lt;/p&gt;
&lt;p&gt;This is initially set to null, but when a method is called the delegate is made to refer to that method:&lt;/p&gt;
&lt;p&gt;private imageProcessItem doBlueTintItem = null;&lt;/p&gt;
&lt;p&gt;private void doBlueTint()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cursor.Current = Cursors.WaitCursor;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessBitmaps.ProcessColor(previewImage, 0, 0, 10);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (doBlueTintItem == null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; doBlueTintItem = new imageProcessItem(doBlueTint);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentItem = doBlueTintItem;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Invalidate();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cursor.Current = Cursors.Default;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Rather than create a new delegate instance each time a method is called, the program instead creates a delegate for each method which is then assigned as appropriate. The code above is called when the user selects the &amp;quot;Blue Tint&amp;quot; option. First it sets the cursor to wait. Next it calls the ProcessColor method - passing it the image and the red, green and blue change value. Then it creates the delegate if required and sets the current item. Finally it puts the cursor back.&lt;/p&gt;
&lt;h4&gt;Sample Project&lt;/h4&gt;
&lt;p&gt;The sample project contains all the above behaviors. A single sprite can be cropped created and will then be moved over a background image, which can be selected and processed as required. The main class, GameForm, implements the movement of the sprites over the background. The MakeSpriteForm class loads in images and provides the user interface for the sprite mask selection and cropping process. The MakeBackgroundForm class loads in images and provides the user interface for the image processing actions. All the actual image processing is provided by the ProcessBitmaps class, which provides a number of static methods that perform the appropriate image updates.&lt;/p&gt;
&lt;h4&gt;Future Work&lt;/h4&gt;
&lt;p&gt;The program at the moment does the image capture and processing, but it does not include any of the game behavior. It is also not possible to perform any image processing on the sprites themselves. Adding these features, and making a game out of the supplied sprites would not be difficult, and is left as an exercise for the reader.&lt;/p&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=7" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Graphics" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Graphics/default.aspx" /></entry><entry><title>Don’t Fear the Garbage Collector</title><link rel="alternate" type="text/html" href="http://community.opennetcf.com/articles/cf/archive/2007/08/10/don-t-fear-the-garbage-collector.aspx" /><id>http://community.opennetcf.com/articles/cf/archive/2007/08/10/don-t-fear-the-garbage-collector.aspx</id><published>2007-08-11T00:13:00Z</published><updated>2007-08-11T00:13:00Z</updated><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;Chris Tacke&lt;br /&gt;OpenNETCF Consulting&lt;br /&gt;August, 2007&lt;/p&gt;  &lt;p&gt;&lt;a class="" title="Download the PDF" href="http://community.opennetcf.com/blogs/cf/200708/Don&amp;#39;t%20Fear%20the%20GC.pdf" target="_blank"&gt;&lt;img height="30" src="http://community.opennetcf.com/blogs/cf/Adobe.PNG" align="middle" border="0" alt="" /&gt;Download the PDF&lt;/a&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We here at OpenNETCF Consulting just delivered version 1.0 of a plant floor monitoring system running on an x86 device with CE 5.0.&amp;nbsp; Since the application was designed for data collection and reporting, we naturally leveraged the .NET Compact Framework version 2.0 and our own Smart Device Framework to meet their functional requirements within a very aggressive schedule.&lt;/p&gt;  &lt;p&gt;As we got to the point where we had most of the functionality nailed down, both the customer as well as us started to get a bit concerned about the overall performance of the application.&amp;nbsp; As we added features the application&amp;#39;s throughput dropped, and it was getting to the point of unacceptable.&lt;/p&gt;  &lt;p&gt;Of course the application is very complex, with multiple processes using lots of threads.&amp;nbsp; Managed and native threads routing data to and from a database through all sorts of communications layers (we&amp;#39;ll look at the app in more detail in another article).&amp;nbsp; So what is a developer to do?&amp;nbsp; Where do you start to look for areas that you rework or refactor to improve overall solution performance?&lt;/p&gt;  &lt;p&gt;One behavior that we found peculiar was a fairly consistent periodicity to the application&amp;#39;s throughput.&amp;nbsp; We have statistical counters that track message throughput of the application and we&amp;#39;d watch it oscillate, running up to 10 or 12 messages a seconds for a few seconds, dropping down to zero, then ramping back up over and over.&lt;/p&gt;  &lt;p&gt;My gut feeling was that we were seeing an artifact of Garbage Collection (GC), but before jumping into the code and blindly assuming that I was correct, we needed some data to prove the theory one way or another.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Garbage Collection&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Before we dive into how we went about testing this theory, it&amp;#39;s important to understand how we came up with the theory in the first place.&amp;nbsp; What about the general behavior of the application led me to infer that this might be a root cause of the problem?&amp;nbsp; To answer that question we need to take a short side trip and look at how the GC works at least at a high level.&amp;nbsp; For more in-depth coverage of how the GC does what it does, take a look at my MSDN WebCast[1] as well as the blog entries from Scott Holden[2] and Steven Pratschner[3] of the .NET Compact Framework team.&lt;/p&gt;  &lt;p&gt;When an application creates an instance of a reference-type object, the allocation must be backed by physical memory.&amp;nbsp; When the object is no longer in use, that memory can be released back to the system for our application or any other to use. As managed code developers, we&amp;#39;re protected from the ugly sausage-making task of allocating and freeing the physical memory, instead we rely on the Compact Framework to cleanly handle all of this for us.&lt;/p&gt;  &lt;p&gt;The GC&amp;#39;s algorithms for how it does all of this work can be a bit complex, but at a high level what it does is allocate large blocks of physical memory which it then divides into smaller &amp;quot;chunks&amp;quot; that it uses to hold our object instances.&amp;nbsp; As we destroy objects, it logically frees those chunks but doesn&amp;#39;t necessarily free the physical memory backing it.&amp;nbsp; The GC&amp;#39;s collection of these blocks is called the GC Heap.&lt;/p&gt;  &lt;p&gt;As our application plods along creating and destroying objects, &amp;quot;holes&amp;quot; are created in the GC Heap where destroyed objects once resided.&amp;nbsp; The GC keeps track of these holes and when certain thresholds or triggers are passed, it goes in and cleans them up by running finalizers, possibly shifting around the in-use blocks to collect the free space together (think of a disk defrag) and sometimes even freeing some of the allocated physical memory.&amp;nbsp; This process is known as Garbage Collection or just Collection.&lt;/p&gt;  &lt;p&gt;In order to do perform Collection, the GC has to make sure everything in the application is in a known safe and stable state.&amp;nbsp; It does this by suspending all threads in the application (think of the problems you&amp;#39;d have if a Thread was accessing some property of a class instance while at the same time the GC was moving it in memory).&amp;nbsp; It is this action - the suspension of all threads in the application - that is what many developers fear, and is what I suspected was causing the periodic performance fluctuations we were seeing.&amp;nbsp; If the GC was collecting with a similar frequency as our lows in throughput performance, it would be strong evidence that it was the culprit.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Remote Performance Monitor&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The first step in checking the theory that the Garbage Collector was our performance-thief was to collect solid data.&amp;nbsp; Fortunately Microsoft has provided managed developers a tool called Remote Performance Monitor (RPM).&amp;nbsp; RPM has been around since version 1.0 of the Compact Framework, but unfortunately it doesn&amp;#39;t seem to get much press short of a couple blog entries[4] and presentations for those fortunate enough to attend shows like MEDC.&lt;/p&gt;  &lt;p&gt;RPM is a cool tool, even up through version 2.0 (though the 3.5 version has some features that will blow you away[5]), provided you know what to make of all of the data it spews out.&amp;nbsp; Essentially what it provides is a live view of a litany of counters from the CLR.&amp;nbsp; It provides the ability to save of views of the data, and even the ability to &amp;quot;publish&amp;quot; the data to PerfMon on the desktop so you can get nice trend graphs of variables over time.&lt;/p&gt;  &lt;p&gt;To test our theory, however, we didn&amp;#39;t need much data.&amp;nbsp; We simply wanted a general sense of how much memory we were allocating in our application and how often the Garbage Collector was performing Collections and compactions.&lt;/p&gt;  &lt;p&gt;So I fired up RPM, launched our primary data collection application through the RPM interface, and had it collect data for about a half hour while I went and had a cup of coffee.&amp;nbsp; Never trust the results of short term test runs, and never analyze data without a good dose of caffeine.&amp;nbsp; Here are some of the statistics from that first half-hour run.&lt;/p&gt;  &lt;div style="PADDING-LEFT:5px;"&gt;  &lt;table class="table" cellspacing="0" cellpadding="0" align="center" class="table"&gt;    &lt;tr&gt;  &lt;td class=""&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt; &lt;/td&gt;  &lt;td class=""&gt;&lt;b&gt;Category&lt;/b&gt; &lt;/td&gt;  &lt;td class=""&gt;&lt;b&gt;Counter&lt;/b&gt; &lt;/td&gt;  &lt;td class=""&gt;&lt;b&gt;Value&lt;/b&gt; &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;1 &lt;/td&gt;  &lt;td class=""&gt;Loader &lt;/td&gt;  &lt;td class=""&gt;Total Program Run Time (ms) &lt;/td&gt;  &lt;td class="" align="right"&gt;1,695,518 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;2 &lt;/td&gt;  &lt;td class=""&gt;Loader &lt;/td&gt;  &lt;td class=""&gt;Methods Loaded &lt;/td&gt;  &lt;td class="" align="right"&gt;5,190 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;3 &lt;/td&gt;  &lt;td class=""&gt;Loader &lt;/td&gt;  &lt;td class=""&gt;Classes Loaded &lt;/td&gt;  &lt;td class="" align="right"&gt;1,623 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;4 &lt;/td&gt;  &lt;td class=""&gt;Loader &lt;/td&gt;  &lt;td class=""&gt;Assemblies Loaded &lt;/td&gt;  &lt;td class="" align="right"&gt;23 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;5 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Total Bytes In Use After G &lt;/td&gt;  &lt;td class="" align="right"&gt;3,310,272 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;6 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Pinned Objects &lt;/td&gt;  &lt;td class="" align="right"&gt;489,219 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;7 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Peak Bytes Allocated (native + managed) &lt;/td&gt;  &lt;td class="" align="right"&gt;4,006,896 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;8 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Objects Not Moved by Compactor &lt;/td&gt;  &lt;td class="" align="right"&gt;2,010,250 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;9 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Objects Moved by Compactor &lt;/td&gt;  &lt;td class="" align="right"&gt;1,306,894 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;10 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Objects Finalized &lt;/td&gt;  &lt;td class="" align="right"&gt;280,433 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;11 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Managed String Objects Allocated &lt;/td&gt;  &lt;td class="" align="right"&gt;2,189,191 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;12 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Managed Objects Allocated &lt;/td&gt;  &lt;td class="" align="right"&gt;7,138,911 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;13 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Managed Bytes In Use After GC &lt;/td&gt;  &lt;td class="" align="right"&gt;548,092 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;14 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Managed Bytes Allocated &lt;/td&gt;  &lt;td class="" align="right"&gt;440,733,748 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;15 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;GC Latency Time (ms) &lt;/td&gt;  &lt;td class="" align="right"&gt;14,702 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;16 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;GC Compactions &lt;/td&gt;  &lt;td class="" align="right"&gt;409 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;17 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Collections (GC) &lt;/td&gt;  &lt;td class="" align="right"&gt;412 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;18 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Code Pitchings &lt;/td&gt;  &lt;td class="" align="right"&gt;2 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;19 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Calls to GC.Collect &lt;/td&gt;  &lt;td class="" align="right"&gt;0 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;20 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Bytes of String Objects Allocated &lt;/td&gt;  &lt;td class="" align="right"&gt;184,459,896 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;21 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Bytes Collected By GC &lt;/td&gt;  &lt;td class="" align="right"&gt;440,063,976 &lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;  &lt;td class=""&gt;22 &lt;/td&gt;  &lt;td class=""&gt;GC &lt;/td&gt;  &lt;td class=""&gt;Boxed Value Types &lt;/td&gt;  &lt;td class="" align="right"&gt;531,631 &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;I&amp;#39;ve numbered each line so we can run through them and discuss what each number means.&lt;/p&gt;  &lt;p&gt;You can see from line 1 that we had a run time of 28 minutes 15.518 seconds.&amp;nbsp; Lines 2-4 say that the loader loaded 5190 methods and 1623 classes out of 23 separate assemblies during this run period.&lt;/p&gt;  &lt;p&gt;Line 5: At the time this view was captured, there was about 3.3MB in use by the application immediately following the most recent Collection.&lt;/p&gt;  &lt;p&gt;Line 6: The GC has encountered nearly half a million pinned objects during its Collections (see line 17).&lt;/p&gt;  &lt;p&gt;Line 7: The maximum amount of allocated memory in use at any given time through this run was just over 4MB.&lt;/p&gt;  &lt;p&gt;Line 8: Just over 2 million objects were not moveable during compaction.&amp;nbsp; This indicates a high number of pinned objects when coupled with Lines 9 and 16.&lt;/p&gt;  &lt;p&gt;Line 9: A cumulative total of 1.3 million objects were moved during Compactions (line 16).&lt;/p&gt;  &lt;p&gt;Line 10: 280 thousand items had to be Finalized.&amp;nbsp; Any item with a finalizer survives two GC Collections before its GC Heap allocation is completely freed [5].&amp;nbsp; This seems like a lot, but it&amp;#39;s not evident immediately whether these are from our application or from assemblies were using (e.g. SQL CE or the CF itself).&amp;nbsp; If this were causing a problem, I&amp;#39;d expect the GC heap to be having size problems, which I don&amp;#39;t think is the case, so it doesn&amp;#39;t cause me any undue concern.&lt;/p&gt;  &lt;p&gt;Line 11: We&amp;#39;ve allocated over 2.1 million strings in 28 minutes.&amp;nbsp; While not overly alarming, it is the most suspect thing so far. That&amp;#39;s a rate of about 1290 string allocations per second. This is a potential source of garbage and looking at the code to try to reduce this rate might be a good idea.&lt;/p&gt;  &lt;p&gt;Line 12: We&amp;#39;ve allocated over 7.1 million managed object in 28 minutes.&amp;nbsp; Again this isn&amp;#39;t overly alarming, but it does mean that we&amp;#39;re allocating objects at a rate of over 4200 per seconds.&amp;nbsp; We might want to investigate places in the code where objects are created instead of reused.&amp;nbsp; It&amp;#39;s also interesting that roughly 30% of our total allocations have been strings (see line 11).&amp;nbsp; It doesn&amp;#39;t mean a lot by itself, but it&amp;#39;s a data point to remember as I profile other applications.&lt;/p&gt;  &lt;p&gt;Line 13:&amp;nbsp; We had 548kB of managed objects still live after the last GC.&amp;nbsp; When we couple this statistic with line 5 (bytes in use after GC) we see that a large amount of our allocations appear to be unmanaged.&amp;nbsp; Due to the architecture of this application, that doesn&amp;#39;t surprise me, so it&amp;#39;s not a cause for concern.&lt;/p&gt;  &lt;p&gt;Line 14:&amp;nbsp; In 28 minutes we&amp;#39;ve allocated over 440MB of data.&amp;nbsp; Wow.&amp;nbsp; That&amp;#39;s a lot of allocation.&lt;/p&gt;  &lt;p&gt;Line 15: We&amp;#39;ve had a GC latency of almost 15 seconds.&amp;nbsp; More on this one later.&lt;/p&gt;  &lt;p&gt;Lines 16-17: We&amp;#39;ve had 412 Collections and 409 Compactions.&amp;nbsp; That means we&amp;#39;re collecting on average once every 4.1 seconds, and nearly every Collection also requires a compaction.&amp;nbsp; This means we&amp;#39;re generating a lot of garbage, and the GC Heap is quite fragmented.&lt;/p&gt;  &lt;p&gt;Line 18: We&amp;#39;ve only had to pitch code twice.&amp;nbsp; This tells me we&amp;#39;re not having any low-memory conditions.&lt;/p&gt;  &lt;p&gt;Line 19: Our code never calls GC.Collect.&amp;nbsp; Nothing more to be said.&lt;/p&gt;  &lt;p&gt;Line 20: Coupled with line 11 (bytes of string objects) this tells me that our string objects average about 26 bytes each.&amp;nbsp; Considering that we&amp;#39;re Unicode and that managed strings also carry a 4-byte length with them, each string is, on average, less than 10 characters.&amp;nbsp; That&amp;#39;s a lot of small strings.&amp;nbsp; Again, seeing if we can reuse string might be worthwhile.&lt;/p&gt;  &lt;p&gt;Line 21: This number is really close to Line 14 (managed bytes allocated).&amp;nbsp; This tells me that we&amp;#39;re probably not leaking and memory, we&amp;#39;re just churning a whole lot of it.&lt;/p&gt;  &lt;p&gt;Line 22: This says we have a boxing rate of over 300 boxing operations a second.&amp;nbsp; While not distressing, we might want to at least look around and see if there&amp;#39;s some obvious place that we&amp;#39;re getting implicit boxing that we don&amp;#39;t need.&lt;/p&gt;  &lt;p&gt;So what do all these statistics means when looked at in aggregate?&amp;nbsp; I see a whole lot of allocation and collection.&amp;nbsp; This system is designed to run 24/7, so if we extrapolate out these numbers to a day of running we would then estimate that we&amp;#39;d churn (allocate and release) nearly 23 Gigabytes of data and Collect over 21,000 times.&amp;nbsp; Sounds a bit frightening in those terms doesn&amp;#39;t it?&lt;/p&gt;  &lt;p&gt;The real gem of information here, though, is line 15 - GC Latency.&amp;nbsp; This is the total amount of time that was spent by the system doing those 412 Collections and it&amp;#39;s only 14.7 seconds.&amp;nbsp; That means each collection is really taking only about 35 milliseconds.&amp;nbsp; To bring that even further into perspective, we spent 14.7 seconds out of over 28 minutes collecting, so or about 0.87% of our execution time.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;So while the raw numbers look big, we&amp;#39;re actually spending less than 1% of our total execution time doing collections.&amp;nbsp; My first reaction to this fact was to re-run all of my calculations.&amp;nbsp; My second reaction was one of amazement and reverence.&amp;nbsp; The Compact Framework team has obviously done a hell of a good job refining the GC&amp;#39;s algorithms and they deserve recognition for that.&amp;nbsp; The Collection statistics for this application could have been much, much worse if they hadn&amp;#39;t done such a good job.&lt;/p&gt;  &lt;p&gt;Does this mean I can rest easy?&amp;nbsp; Not at all. We&amp;#39;re still churning a lot of data and creating a whole lot of objects.&amp;nbsp; It&amp;#39;s still a worthwhile exercise to go in and spend a couple hours trying to reduce the both the Collection and churn rate, but it also means that we&amp;#39;re going to quickly have diminishing returns.&amp;nbsp; Spending a days or weeks trying to eke out every last performance gain would be foolish.&lt;/p&gt;  &lt;p&gt;In fact I did revisit the code and spent about two hours reworking some of the code to reduce allocations.&amp;nbsp; It turned out that we were generating a lot of debugging information that we used for logging even when the logging was turned off (the objects were created, just never used).&amp;nbsp; After cleaning this, and a few other areas up I got the GC rate down to about once every 6 seconds, or about 0.6% of run time which is nearly a 50% improvement, but the reality was that it was still a very miniscule part of the overall run and it lead to no noticeable improvement in throughput.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;So what did we learn from this exercise, other than we needed to look elsewhere for the performance bottle necks (they turned out to be in our usage of the SQL CE database, and I&amp;#39;ll be going into depth on what we learned there in a later article)?&lt;/p&gt;  &lt;p&gt;Don&amp;#39;t fear GC.&amp;nbsp; The GC has an extremely important job.&amp;nbsp; It is the magic box that allows us to worry about our architecture and not about memory leaks, buffer overruns and access violations.&amp;nbsp; The Compact Framework team has made the GC work well and as transparent as we could hope (though I definitely don&amp;#39;t want them to stop trying to improve it or allowing us to have more control over it).&amp;nbsp; The GC allows us to develop far more stable code in a much shorter period of time, and we must accept that it&amp;#39;s not something to be feared or avoided.&lt;/p&gt;  &lt;p&gt;We also got a little practice in using the tools Microsoft provides to help us analyze our systems.&amp;nbsp; Without tools like this we&amp;#39;d be left guessing about what to work on and I&amp;#39;d probably still be trying to reduce the garbage the application is creating.&lt;/p&gt;  &lt;p&gt;We still need to be cognizant of the garbage we create, but maybe in the future the first thing that comes to mind when we have a performance problem shouldn&amp;#39;t be the Garbage Collector or the runtime.&amp;nbsp; Instead maybe we should instead ask ourselves what mistake we made in our own architecture or implementation.&amp;nbsp; After all even the best system can&amp;#39;t compensate for poor code, and none of us are immune to making mistakes no matter how much experience we have.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;References&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;[1] &lt;a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032318790&amp;amp;Culture=en-US"&gt;http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032318790&amp;amp;Culture=en-US&lt;/a&gt; &lt;br /&gt;[2] &lt;a href="http://blogs.msdn.com/scottholden/archive/2004/12/28/339733.aspx"&gt;http://blogs.msdn.com/scottholden/archive/2004/12/28/339733.aspx&lt;/a&gt; &lt;br /&gt;[3] &lt;a href="http://blogs.msdn.com/stevenpr/archive/tags/GC/default.aspx"&gt;http://blogs.msdn.com/stevenpr/archive/tags/GC/default.aspx&lt;/a&gt; &lt;br /&gt;[4] &lt;a href="http://blogs.msdn.com/stevenpr/archive/2006/04/17/577636.aspx"&gt;http://blogs.msdn.com/stevenpr/archive/2006/04/17/577636.aspx&lt;/a&gt; &lt;br /&gt;[5] Microsoft hasn&amp;#39;t yet officially published any RPM 3.5 stuff, but when they do we&amp;#39;ll update this reference&lt;br /&gt;[6] &amp;lt;Insert link to MEDC decks on Community&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Also See Reference 1&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://community.opennetcf.com/aggbug.aspx?PostID=5" width="1" height="1"&gt;</content><author><name>ctacke</name><uri>http://community.opennetcf.com/members/ctacke.aspx</uri></author><category term="Garbage Collector" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Garbage+Collector/default.aspx" /><category term="Compact Framework" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Compact+Framework/default.aspx" /><category term="Remote Performance Monitor" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Remote+Performance+Monitor/default.aspx" /><category term="Debugging" scheme="http://community.opennetcf.com/articles/cf/archive/tags/Debugging/default.aspx" /></entry></feed>
