<?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.openn