<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>public: class Alon : IArchitect, IAzure, ICPP, ISmartHome, IHomeServer</title><link>http://blogs.microsoft.co.il/blogs/alon/</link><description>The smart virtual home of Alon Fliess</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Message Only Window in for .NET Application</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/12/26/message-only-window-in-for-net-application.aspx</link><pubDate>Mon, 26 Dec 2011 19:16:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:969856</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=969856</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=969856</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/12/26/message-only-window-in-for-net-application.aspx#comments</comments><description>&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;
&lt;h4&gt;Overview&lt;/h4&gt;
&lt;p&gt;.NET is great platform, it speeds up the development process, you deal with your application logic and in most cases you don&amp;#39;t need to know that there is whole Windows operating system down there. However sometimes you do need to program against Windows without the .NET assistance. As a Windows developer, you need to keep all your weapons ready, be it .NET, COM or C++ with the native Win32 API. In this article I am going to show how to deal with Windows Message based communication protocol within .NET application.&lt;/p&gt;
&lt;h4&gt;Windows Messages &lt;/h4&gt;
&lt;p&gt;In traditional &lt;font face="Consolas"&gt;User32.dll&lt;/font&gt; based Windows application the Windows Messages mechanism serves as a communication channel among many parties. The Windows Operating System uses this mechanism to ask the Window to draw itself, to inform about environmental change or even to communicate a logoff event. The application itself uses this mechanism to create an event driven design model with a single thread or to communicate between threads. Other applications can use this mechanism with an application defined message (the &lt;font face="Consolas"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644930(v=vs.85).aspx" target="_blank"&gt;WM_APP&lt;/a&gt;&lt;/font&gt; message range) to trigger a logical event, or even to pass memory buffer using the &lt;font face="Consolas"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms649011(v=vs.85).aspx" target="_blank"&gt;WM_COPYDATA&lt;/a&gt;&lt;/font&gt;. &lt;/p&gt;
&lt;h4&gt;Windows In Windows Are Based On An Object Oriented Mechanism&lt;/h4&gt;
&lt;p&gt;One of the impressive thing about the windows mechanism of Windows, considering its age and the fact that it was implemented with the C language in mind, is that is based on the Object Oriented paradigm. Each window is belong to a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632596(v=vs.85).aspx" target="_blank"&gt;Window Class&lt;/a&gt;. The class is the factory of a window. The class defines the window&amp;#39;s properties as well as the window&amp;#39;s behavior. The properties are set using one of the predefined window class member such as the window&amp;#39;s menu, or cursor. The behavior is defined by specifying the windows procedure address. The window procedure handles the incoming Windows Messages, which are in fact the methods of the window. Changing the Windows attributes can be made using the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;SetWindowLong&lt;/font&gt;&lt;/a&gt;&lt;font face="Consolas"&gt;/&lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=VS.85).aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;Ptr&lt;/font&gt;&lt;/a&gt;. Creating type fields (static) and instance fields can be made by allocating user-defined memory area for each Window class (static) and Window instance (dynamic) using the &lt;font face="Consolas"&gt;cbClsExtra&lt;/font&gt; and &lt;font face="Consolas"&gt;cbWndExtra&lt;/font&gt; fields of the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;WNDCLASS&lt;/font&gt;&lt;/a&gt; structure. Subclassing a Windows class can be achieved by changing the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633569(v=vs.85).aspx" target="_blank"&gt;window procedure&lt;/a&gt; address to point to a custom function that handles the Windows Messages before it calls the original window procedure. You can subclass a Window instance or Window class (global subclassing).&lt;/p&gt;
&lt;h4&gt;Windows Do Not Run&lt;/h4&gt;
&lt;p&gt;In first look, it seems that that message communication is based on one window sending messages to another window, however windows do not run, threads do. Windows makes a correlation between threads and windows. The thread that calls &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679(v=vs.85).aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;CreateWindow&lt;/font&gt;&lt;/a&gt;&lt;font face="Consolas"&gt;/&lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;Ex&lt;/font&gt;&lt;/a&gt; is the thread that receives the Windows Messages related to this Window. In a common implementation of a Windows application, the main thread creates it&amp;#39;s main and child windows, and then starts a message loop, also known as message pump, pumping messages that has been sent to any of it&amp;#39;s windows, and dispatching this messages to the correct Window Procedure – the code that handle Windows Messages on behalf of the target Window. &lt;/p&gt;
&lt;h4&gt;Using Windows Messages Not For Painting The Window&lt;/h4&gt;
&lt;p&gt;Passing Windows Messages is one of the most easier inter process communication (IPC) mechanism, especially if the two parties are already implementing the Windows message handling boilerplate to handle their UI. One of the compelling feature of the mechanism is that it serves as a base for thread function call dispatching, enables a cross thread context call. For example in COM Single Threaded Apartment (STA), COM uses Windows Messages to dispatch function calls to the thread that created the component, much the same as dispatching messages to the windows created by the thread. This ensures that all the code of the COM component will be executed in a single thread- the idea behind the STA model.&amp;nbsp; &lt;/p&gt;
&lt;h4&gt;Message Only Window&lt;/h4&gt;
&lt;p&gt;There are cases that you need to communicate using Windows Messages with another application or component, but your application is not based on the traditional &lt;font face="Consolas"&gt;user32.dll&lt;/font&gt; Windows. This happens more and more in modern native and manage applications that are based on Console or DirectX, for example a .NET WPF based application. In such cases there is no need to create a window to handle these messages, since we do not care about painting the window or handling resize messages, we do not want to pay the cost of such a mechanism and we do not want to handle the hiding of such a window. For that in Windows 2000 Microsoft has added a new type of window type, the message-only-window. Creating such a window is very easy, all you need to do is to provide the &lt;font face="Consolas"&gt;HWND_MESSAGE&lt;/font&gt; as the window&amp;#39;s parent. You can do that in the &lt;font face="Consolas"&gt;CreateWindow/Ex&lt;/font&gt; or by using the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633541(v=VS.85).aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;SetParent&lt;/font&gt;&lt;/a&gt; function. You can use any predefined Window class, for example &lt;font face="Consolas"&gt;&amp;quot;STATIC&amp;quot;&lt;/font&gt;, or &lt;font face="Consolas"&gt;&amp;quot;Message&amp;quot;&lt;/font&gt;, as long as you subclass the window procedure to handle the coming Windows Messages. &lt;/p&gt;
&lt;h4&gt;Building A Message-Only-Window Client For .NET Applications&lt;/h4&gt;
&lt;p&gt;For handling system event, the .NET framework provides the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx" target="_blank"&gt;&lt;font face="Consolas"&gt;Microsoft.Win32.SystemEvents&lt;/font&gt;&lt;/a&gt; class. However this class is made to receive Windows system event messages and can&amp;#39;t be extended to receive custom user messages. You can always use &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163417.aspx" target="_blank"&gt;Windows Form window to handle windows messages&lt;/a&gt;, however you will need to add reference to &lt;font face="Consolas"&gt;System.Windows.Forms.dll&lt;/font&gt; even if you don&amp;#39;t use Windows Forms, and you will need to hide the form.&amp;nbsp; A second approach, which I took, is to use C++/CLI assembly to create a message-only-window proxy. In this mechanism a native code handles the windows messages dispatching boilerplate. All is left for the managed code is to register a callback delegate on the message received event and ask the mechanism to start the message loop in the context of the thread that should handle the coming windows messages.&lt;/p&gt;
&lt;h4&gt;The Design&lt;/h4&gt;
&lt;p&gt;The &lt;font face="Consolas"&gt;NativeMessageOnlyWindow&lt;/font&gt; is a native class that handles the windows messages receiving, dispatching and handling. The &lt;font face="Consolas"&gt;MessageOnlyWindow&lt;/font&gt; is a managed C++/CLI wrapper (adapter) class that serves as the .NET interface for the mechanism. To bridge between the two, the &lt;font face="Consolas"&gt;MessageOnlyWindow&lt;/font&gt; class instantiates the native instance of the &lt;font face="Consolas"&gt;NativeMessageOnlyWindow&lt;/font&gt; and keeps it as a member that will be deleted on dispose.&amp;nbsp; The managed &lt;font face="Consolas"&gt;MessageOnlyWindow&lt;/font&gt; class implements the &lt;font face="Consolas"&gt;IMessageCallback&lt;/font&gt; interface. The native &lt;font face="Consolas"&gt;NativeMessageOnlyWindow&lt;/font&gt; gets and holds a &lt;font face="Consolas"&gt;gcroot&amp;lt;IMessageCallback ^&amp;gt;&lt;/font&gt; to the &lt;font face="Consolas"&gt;MessageOnlyWindow&lt;/font&gt; managed class in the constructor. When the &lt;font face="Consolas"&gt;NativeMessageOnlyWindow&lt;/font&gt; receives Windows messages it calls to the &lt;font face="Consolas"&gt;OnMessageReceivedCallback&lt;/font&gt; method of the &lt;font face="Consolas"&gt;IMessageCallback&lt;/font&gt; interface. To get a better understanding on calling from native to .NET see &lt;a href="http://blogs.microsoft.co.il/blogs/alon/archive/2007/05/29/Native-Callback.aspx" target="_blank"&gt;this blog post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_1A7452BD.png"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-RIGHT-WIDTH:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;PADDING-TOP:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_683CDCA5.png" width="710" height="516" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To start pumping messages, the .NET client calls the &lt;font face="Consolas"&gt;MessageOblyWindow&lt;/font&gt; instance &lt;font face="Consolas"&gt;StartMessageLoop&lt;/font&gt; method. The call has to be made by the thread that created the Window that need to be handled. This call will not return until a call to &lt;font face="Consolas"&gt;StopMessageLoop&lt;/font&gt; will be made from any arbitrary thread.&lt;/p&gt;
&lt;h4&gt;The &lt;font face="Consolas"&gt;MessagePump.h&lt;/font&gt; header file&lt;/h4&gt;
&lt;div class="csharpcode"&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   1:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   2:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   3:  &lt;/span&gt;&lt;span style="COLOR:#008000;" class="rem"&gt;// MessagePump.h&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   4:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   5:  &lt;/span&gt;&lt;span style="COLOR:#cc6633;" class="preproc"&gt;#pragma&lt;/span&gt; once&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   6:  &lt;/span&gt;#include &amp;lt;Windows.h&amp;gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   7:  &lt;/span&gt;#include &amp;lt;hash_map&amp;gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   8:  &lt;/span&gt;#include &amp;lt;vcclr.h&amp;gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   9:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  10:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  11:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; std;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  13:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; MessagePump &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  14:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  15:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;//Callback wrapper &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  16:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;interface&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;class&lt;/span&gt; IMessageCallback&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  17:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  18:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//get called each time a new message is arrived to the message only window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  19:  &lt;/span&gt;        IntPtr OnMessageReceivedCallback(IntPtr hWnd, UINT message, WPARAM wParam, LPARAM lParam);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  20:  &lt;/span&gt;    };&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  21:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  22:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;//Serves as a Windows Message Loop manager for the message only window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  23:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;class&lt;/span&gt; NativeMessageOnlyWindow&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  24:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  25:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;private&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  26:  &lt;/span&gt;        HWND m_hWnd;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  27:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;bool&lt;/span&gt; m_bStop;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  28:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  29:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//This map helps in correlating the hWnd we get in the WndProc to the &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  30:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//NativeMessageOnlyWindow instance of that Window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  31:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;static&lt;/span&gt; hash_map&amp;lt;HWND, NativeMessageOnlyWindow *&amp;gt; s_windowsMap;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  32:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  33:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Enables calling back to .NET interface method&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  34:  &lt;/span&gt;        gcroot&amp;lt;IMessageCallback ^&amp;gt; _messageCallback;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  35:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  36:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//To stop the message loop, we need to call PostQuitMessage in the context of the &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  37:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//message loop thread. To do that we are sending this message&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  38:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;static&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;const&lt;/span&gt; unsigned &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;int&lt;/span&gt; WM_APPSTOP = WM_APP + 242;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  39:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  40:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Create the message only window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  41:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; Create();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  42:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  43:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//The WndProc for the message only window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  44:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;static&lt;/span&gt; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  45:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  46:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  47:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  48:  &lt;/span&gt;        NativeMessageOnlyWindow(&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;const&lt;/span&gt; gcroot&amp;lt;IMessageCallback ^&amp;gt; &amp;amp;&amp;amp;callback) : m_hWnd(0), &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  49:  &lt;/span&gt;            m_bStop(&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;false&lt;/span&gt;), _messageCallback(callback) {}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  50:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  51:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Stop the message loop, the actual stop happens asynchronously, since &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  52:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//we use PostQuitMessage&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  53:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; StopMessageLoop();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  54:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  55:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//A blocking call, the message loop is in the context of the calling thread&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  56:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; StartMessageLoop(); &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  57:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  58:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Return the message only window handle&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  59:  &lt;/span&gt;        HWND GetWindowHandle() &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;const&lt;/span&gt; { &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; m_hWnd; }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  60:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  61:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Stop the message loop and destroy the instance&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  62:  &lt;/span&gt;        ~NativeMessageOnlyWindow();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  63:  &lt;/span&gt;    };&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  64:  &lt;/span&gt;    &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  65:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  66:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;/// Represents a Windows Message that encapsulate in .NET type the WndProc arguments&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  67:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  68:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;value&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;class&lt;/span&gt; WindowsMessage&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  69:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  70:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;private&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  71:  &lt;/span&gt;        IntPtr            m_hwnd;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  72:  &lt;/span&gt;        unsigned &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;int&lt;/span&gt;    m_uMessage;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  73:  &lt;/span&gt;        UIntPtr            m_wParam;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  74:  &lt;/span&gt;        IntPtr            m_lParam;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  75:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  76:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  77:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  78:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Construct a new WindowsMessage class that holds the WndProc arguments&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  79:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  80:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;hWnd&amp;quot;&amp;gt;The target windows handle&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  81:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;message&amp;quot;&amp;gt;The message number&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  82:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;wParam&amp;quot;&amp;gt;the wParam&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  83:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;lParam&amp;quot;&amp;gt;the lParam&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  84:  &lt;/span&gt;        WindowsMessage(IntPtr hWnd, UINT message, WPARAM wParam, LPARAM lParam) : &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  85:  &lt;/span&gt;          m_hwnd(hWnd), m_uMessage(message), m_wParam(UIntPtr(wParam)), m_lParam(IntPtr(lParam)) {}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  86:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  87:  &lt;/span&gt;        property IntPtr HWnd { IntPtr get() { &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; m_hwnd; }}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  88:  &lt;/span&gt;        property unsigned &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;int&lt;/span&gt; Message { unsigned &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;int&lt;/span&gt; get() { &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; m_uMessage; }}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  89:  &lt;/span&gt;        property UIntPtr WParam { UIntPtr get() { &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; m_wParam; }}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  90:  &lt;/span&gt;        property IntPtr LParam { IntPtr get() { &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; m_lParam; }}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  91:  &lt;/span&gt;    };&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  92:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  93:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  94:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///Use this class to create a message only window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  95:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  96:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  97:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///With this class you can receive Windows Messages without the need to use a WinForm instance.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  98:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///Message only windows are lightweight mechanisms that serves only for receiving windows messages.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  99:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 100:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;ref&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;class&lt;/span&gt; MessageOnlyWindow : &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; IMessageCallback &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 101:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 102:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;private&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 103:  &lt;/span&gt;        NativeMessageOnlyWindow *m_pNativeMessageOnlyWindow;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 104:  &lt;/span&gt;    &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 105:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;protected&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 106:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 107:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// This callback functions receives the raw WndProc arguments for any message that has been &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 108:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// sent to the message-only-window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 109:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 110:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;hWnd&amp;quot;&amp;gt;The target windows handle&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 111:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;message&amp;quot;&amp;gt;The message number&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 112:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;wParam&amp;quot;&amp;gt;the wParam&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 113:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;param name=&amp;quot;lParam&amp;quot;&amp;gt;the lParam&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 114:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;returns&amp;gt;The method should return a value for the DefWndProc, usually &amp;lt;see cref=&amp;quot;IntPtr::Zero&amp;quot;/&amp;gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 115:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// is suitable&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 116:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;remarks&amp;gt;When overriding this method, call the base class implementation to fire the &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 117:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;see cref=&amp;quot;MessageReceived&amp;quot;/&amp;gt; event.&amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 118:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;virtual&lt;/span&gt; IntPtr OnMessageReceivedCallback(IntPtr hWnd, UINT message, WPARAM wParam, LPARAM lParam) &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 119:  &lt;/span&gt;            = IMessageCallback::OnMessageReceivedCallback;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 120:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 121:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt;:&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 122:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 123:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///Constructor for the message only window instance&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 124:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 125:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 126:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///With this instance you can receive Windows Messages without the need to use a WinForm instance.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 127:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///Register a callback on the &amp;lt;see cref=&amp;quot;MessageReceived&amp;quot;/&amp;gt; event and call the &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 128:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;see cref=&amp;quot;StartMessageLoop&amp;quot;/&amp;gt; to start receiving windows messages.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 129:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Call the &amp;lt;see cref=&amp;quot;StopMessageLoop&amp;quot;/&amp;gt; to stop receiving windows messages.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 130:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Dispose the instance whenever you do not need it anymore&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 131:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 132:  &lt;/span&gt;        MessageOnlyWindow();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 133:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 134:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 135:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Fires an event that represents a single windows message that has been sent to &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 136:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// the message-only-window&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 137:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 138:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;event&lt;/span&gt; Func&amp;lt;WindowsMessage, IntPtr&amp;gt; ^MessageReceived;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 139:  &lt;/span&gt;        &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 140:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 141:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Ask the message pump thread to stop. &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 142:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 143:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 144:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// The message pump thread is the thread that called the &amp;lt;see cref=&amp;quot;StartMessageLoop&amp;quot;/&amp;gt;.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 145:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// The stop operations is asynchronously, This call trigger a WM_QUIT message that will &lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 146:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// eventually stop the loop&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 147:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 148:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; StopMessageLoop() { m_pNativeMessageOnlyWindow-&amp;gt;StopMessageLoop(); }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 149:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 150:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 151:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Start the message loop in the context of the calling thread&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 152:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 153:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 154:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// Call this method in the context of the thread that triggered the Windows Messages source.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 155:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// This is a blocking call, the message loop is in the context of the calling thread.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 156:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// This method will be return only after a call to the &amp;lt;see cref=&amp;quot;StopMessageLoop&amp;quot;/&amp;gt;.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 157:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 158:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; StartMessageLoop()  { m_pNativeMessageOnlyWindow-&amp;gt;StartMessageLoop(); }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 159:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 160:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 161:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// The message-only-window handle&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 162:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 163:  &lt;/span&gt;        property IntPtr WindowHandle { IntPtr get() &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 164:  &lt;/span&gt;                { &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; IntPtr(m_pNativeMessageOnlyWindow-&amp;gt;GetWindowHandle()); }}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 165:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 166:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 167:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// clear native resources&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 168:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 169:  &lt;/span&gt;        ~MessageOnlyWindow() { delete m_pNativeMessageOnlyWindow; }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 170:  &lt;/span&gt;    };&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 171:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 172:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;font face="Consolas"&gt;MessagePump.cpp&lt;/font&gt; code file&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   1:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   2:  &lt;/span&gt;&lt;span style="COLOR:#008000;" class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   3:  &lt;/span&gt;&lt;span style="COLOR:#008000;" class="rem"&gt;// Messagepump.cpp&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   4:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   5:  &lt;/span&gt;#include &lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;stdafx.h&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   6:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   7:  &lt;/span&gt;#include &lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;MessagePump.h&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   8:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   9:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  10:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; System::Runtime::InteropServices;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  11:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  13:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; MessagePump &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  14:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  15:  &lt;/span&gt;    MessageOnlyWindow::MessageOnlyWindow() &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  16:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  17:  &lt;/span&gt;        m_pNativeMessageOnlyWindow = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;new&lt;/span&gt; NativeMessageOnlyWindow(gcroot&amp;lt;IMessageCallback ^&amp;gt;(&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;this&lt;/span&gt;));&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  18:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  19:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  20:  &lt;/span&gt;    IntPtr MessageOnlyWindow::OnMessageReceivedCallback(IntPtr hWnd, UINT message, WPARAM wParam, LPARAM lParam)&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  21:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  22:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; MessageReceived(WindowsMessage(hWnd, message, wParam, lParam));&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  23:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  24:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  25:  &lt;/span&gt;    hash_map&amp;lt;HWND, NativeMessageOnlyWindow *&amp;gt; NativeMessageOnlyWindow::s_windowsMap;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  26:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  27:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; NativeMessageOnlyWindow::Create()&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  28:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  29:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Create a Window that can only receive messages&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  30:  &lt;/span&gt;        m_hWnd = CreateWindow(L&lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;Message&amp;quot;&lt;/span&gt;, L&lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, 0, 0, 0, 0, 0, HWND_MESSAGE , nullptr, GetModuleHandle(0), nullptr);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  31:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;if&lt;/span&gt; (m_hWnd == nullptr)&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  32:  &lt;/span&gt;            Marshal::ThrowExceptionForHR(GetLastError());&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  33:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  34:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Set the Window&amp;#39;s WndProc to our Windows Procedure&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  35:  &lt;/span&gt;        auto result = SetWindowLongPtr(m_hWnd, GWLP_WNDPROC, (LONG_PTR)WndProc);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  36:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;if&lt;/span&gt; (result == 0)&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  37:  &lt;/span&gt;            Marshal::ThrowExceptionForHR(GetLastError());&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  38:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  39:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Keep the correlation between the hWnd and the MessageOnlyWindow instance&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  40:  &lt;/span&gt;        s_windowsMap[m_hWnd] = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;this&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  41:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  42:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  43:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; NativeMessageOnlyWindow::StopMessageLoop()&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  44:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  45:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Two stop marks&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  46:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  47:  &lt;/span&gt;        m_bStop = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  48:  &lt;/span&gt;        SendMessage(m_hWnd, WM_APPSTOP, 0, 0); &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  49:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  50:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  51:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  52:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; NativeMessageOnlyWindow::StartMessageLoop()&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  53:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  54:  &lt;/span&gt;        m_bStop = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  55:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Create the Windows&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  56:  &lt;/span&gt;        Create();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  57:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  58:  &lt;/span&gt;        MSG msg;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  59:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  60:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//The traditional message loop&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  61:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;while&lt;/span&gt; (GetMessage(&amp;amp;msg, NULL, 0, 0))&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  62:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  63:  &lt;/span&gt;            TranslateMessage(&amp;amp;msg);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  64:  &lt;/span&gt;            DispatchMessage(&amp;amp;msg);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  65:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  66:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  67:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  68:  &lt;/span&gt;    NativeMessageOnlyWindow::~NativeMessageOnlyWindow()&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  69:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  70:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;if&lt;/span&gt; (m_hWnd == nullptr)&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  71:  &lt;/span&gt;            &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  72:  &lt;/span&gt;        StopMessageLoop();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  73:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  74:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  75:  &lt;/span&gt;    LRESULT CALLBACK NativeMessageOnlyWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  76:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  77:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Find the correlated NativeMessageOnlyWindow instance&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  78:  &lt;/span&gt;        auto iter = s_windowsMap.find(hWnd);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  79:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;if&lt;/span&gt; (iter == s_windowsMap.end()) &lt;span style="COLOR:#008000;" class="rem"&gt;//instance not found&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  80:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  81:  &lt;/span&gt;            OutputDebugString(L&lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;NativeMessageOnlyWindow, a message can&amp;#39;t be dispatched, HWDN not found.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  82:  &lt;/span&gt;            &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; DefWindowProc(hWnd, message, wParam, lParam);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  83:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  84:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  85:  &lt;/span&gt;        auto This = iter-&amp;gt;second;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  86:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  87:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;if&lt;/span&gt; (message == WM_APPSTOP &amp;amp;&amp;amp; This-&amp;gt;m_bStop) &lt;span style="COLOR:#008000;" class="rem"&gt;//Is Stop&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  88:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  89:  &lt;/span&gt;            PostQuitMessage(0); &lt;span style="COLOR:#008000;" class="rem"&gt;//Send WM_QUIT to stop the message loop&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  90:  &lt;/span&gt;            s_windowsMap.erase(iter); &lt;span style="COLOR:#008000;" class="rem"&gt;//Remove the NativeMessageOnlyWindow instance from the hash map&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  91:  &lt;/span&gt;            This-&amp;gt;m_hWnd = nullptr;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  92:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  93:  &lt;/span&gt;            &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; DefWindowProc(hWnd, message, wParam, lParam);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  94:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  95:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  96:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;//Trigger the callback call to the managed wrapper instance&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  97:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; reinterpret_cast&amp;lt;LRESULT&amp;gt;(&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  98:  &lt;/span&gt;            This-&amp;gt;_messageCallback-&amp;gt;OnMessageReceivedCallback(IntPtr(hWnd), message, wParam, lParam).ToPointer());&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  99:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 100:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt; 101:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="csharpcode"&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   1:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   2:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   3:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   4:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   5:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   6:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; System.Threading;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   7:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   8:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; MessagePump;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;   9:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;using&lt;/span&gt; Microsoft.VisualStudio.TestTools.UnitTesting;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  10:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  11:  &lt;/span&gt;&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;namespace&lt;/span&gt; TestMessagePump&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  12:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  13:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  14:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;/// Summary description for UnitTest1&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  15:  &lt;/span&gt;    &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  16:  &lt;/span&gt;    [TestClass]&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  17:  &lt;/span&gt;    &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;class&lt;/span&gt; UnitTestMessagePump&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  18:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  19:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  20:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///Gets or sets the test context which provides&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  21:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///information about and functionality for the current test run.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  22:  &lt;/span&gt;        &lt;span style="COLOR:#008000;" class="rem"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  23:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; TestContext TestContext { get; set; }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  24:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  25:  &lt;/span&gt;        [DllImport(&lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;user32.dll&amp;quot;&lt;/span&gt;, CharSet = CharSet.Auto)]&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  26:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;static&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;extern&lt;/span&gt; IntPtr SendMessage(IntPtr hWnd, UInt32 msg, UIntPtr wParam, IntPtr lParam);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  27:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  28:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  29:  &lt;/span&gt;        [TestMethod]&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  30:  &lt;/span&gt;        &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;public&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;void&lt;/span&gt; TestMethodSendingMessages()&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  31:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  32:  &lt;/span&gt;            var messagePump = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;new&lt;/span&gt; MessageOnlyWindow();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  33:  &lt;/span&gt;            var messageList = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;WindowsMessage&amp;gt;();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  34:  &lt;/span&gt;            var loopHasStarted = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;new&lt;/span&gt; ManualResetEventSlim(&lt;span style="COLOR:#0000ff;" class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  35:  &lt;/span&gt;&lt;span style="COLOR:#008000;" class="rem"&gt;// ReSharper disable InconsistentNaming&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  36:  &lt;/span&gt;            &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;const&lt;/span&gt; &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;uint&lt;/span&gt; WM_APP = 0x8000;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  37:  &lt;/span&gt;&lt;span style="COLOR:#008000;" class="rem"&gt;// ReSharper restore InconsistentNaming&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  38:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  39:  &lt;/span&gt;            messagePump.MessageReceived += message =&amp;gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  40:  &lt;/span&gt;                                               {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  41:  &lt;/span&gt;                                                   &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;lock&lt;/span&gt; (messageList)&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  42:  &lt;/span&gt;                                                   {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  43:  &lt;/span&gt;                                                       messageList.Add(message);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  44:  &lt;/span&gt;                                                   }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  45:  &lt;/span&gt;                                                   loopHasStarted.Set();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  46:  &lt;/span&gt;                                                   &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;return&lt;/span&gt; IntPtr.Zero;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  47:  &lt;/span&gt;                                               };&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  48:  &lt;/span&gt;            &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;bool&lt;/span&gt; loopHasStopped = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  49:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  50:  &lt;/span&gt;            Task.Factory.StartNew(() =&amp;gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  51:  &lt;/span&gt;                                      {&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  52:  &lt;/span&gt;                                          messagePump.StartMessageLoop();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  53:  &lt;/span&gt;                                          loopHasStopped = &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  54:  &lt;/span&gt;                                      });&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  55:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  56:  &lt;/span&gt;            Thread.Sleep(1000);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  57:  &lt;/span&gt;            SendMessage(messagePump.WindowHandle, WM_APP, UIntPtr.Zero, IntPtr.Zero);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  58:  &lt;/span&gt;            var result = loopHasStarted.Wait(1000);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  59:  &lt;/span&gt;            Assert.AreNotEqual(result, &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;false&lt;/span&gt;, &lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;Timeout, a message hasn&amp;#39;t arrived&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  60:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  61:  &lt;/span&gt;            SendMessage(messagePump.WindowHandle, WM_APP + 1, UIntPtr.Zero, IntPtr.Zero);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  62:  &lt;/span&gt;            SendMessage(messagePump.WindowHandle, WM_APP + 2, UIntPtr.Zero, IntPtr.Zero);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  63:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  64:  &lt;/span&gt;            Assert.AreNotEqual(loopHasStopped, &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;true&lt;/span&gt;, &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  65:  &lt;/span&gt;                       &lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;The message Loop should not be stopped until we call the StopMessageLoop&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  66:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  67:  &lt;/span&gt;            messagePump.StopMessageLoop();&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  68:  &lt;/span&gt;            Thread.Sleep(3000);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  69:  &lt;/span&gt;            Assert.AreEqual(loopHasStopped, &lt;span style="COLOR:#0000ff;" class="kwrd"&gt;true&lt;/span&gt;,&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  70:  &lt;/span&gt;                       &lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;The message Loop should stopped since we have called the StopMessageLoop&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  71:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  72:  &lt;/span&gt;            var numberOfAppMessages =&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  73:  &lt;/span&gt;                messageList.Count(&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  74:  &lt;/span&gt;                    message =&amp;gt;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  75:  &lt;/span&gt;                    message.Message == WM_APP || message.Message == WM_APP + 1 || message.Message == WM_APP + 2);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  76:  &lt;/span&gt;                &lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  77:  &lt;/span&gt;           Assert.AreEqual(numberOfAppMessages, 3, &lt;span style="COLOR:#006080;" class="str"&gt;&amp;quot;There should be three WM_APP + x Messages in the list&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  78:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  79:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  80:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  81:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre style="BACKGROUND-COLOR:#ffffff;MARGIN:0em;FONT-FAMILY:consolas, &amp;#39;Courier New&amp;#39;, courier, monospace;COLOR:black;FONT-SIZE:small;"&gt;&lt;span style="COLOR:#606060;" class="lnum"&gt;  82:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Download the VS 2010 solution from &lt;a href="https://skydrive.live.com/redir.aspx?cid=2804458381bc8909&amp;amp;resid=2804458381BC8909!11186&amp;amp;parid=2804458381BC8909!144" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=969856" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B002F00_CLI/default.aspx">C++/CLI</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/VC/default.aspx">VC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Interop/default.aspx">Interop</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/VS+2010/default.aspx">VS 2010</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CPP_2F00_CLI/default.aspx">CPP/CLI</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Windows Platform User Group Next Meeting</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/11/22/windows-platform-user-group-next-meeting.aspx</link><pubDate>Tue, 22 Nov 2011 19:25:35 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:938033</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=938033</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=938033</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/11/22/windows-platform-user-group-next-meeting.aspx#comments</comments><description>&lt;p&gt;I’ve had the chance to take part in the last &lt;a href="http://www.buildwindows.com/" target="_blank"&gt;BUILD&lt;/a&gt; conference. It is true that you don’t have to travel to the other side of the world to get the new knowledge. You can follow the tweets, read the blogs and watch the online videos. However being at the conference gives you the opportunity and time to be focused and the ability to meet people and build your perception about the future of the current and new technologies. And there is a lot to think about: The future of Windows, The future of .NET, The upcoming technology trends (&lt;a href="http://en.wikipedia.org/wiki/Cloud_computing" target="_blank"&gt;Cloud&lt;/a&gt;, Phone, ARM, ALM, …)&amp;#160; &lt;/p&gt;  &lt;p&gt;In our &lt;a href="https://www.microsoft.com/israel/communities/usergroups-wpd.htm" target="_blank"&gt;Windows Platform User Group&lt;/a&gt; &lt;a href="http://blogs.microsoft.co.il/blogs/pavely/" target="_blank"&gt;Pavel&lt;/a&gt; and I will start to get into the new technologies that Microsoft revealed at Build. In the coming meeting &lt;a href="http://blogs.microsoft.co.il/blogs/software_engineering/" target="_blank"&gt;Josh&lt;/a&gt;, a Technical Computing MVP is going to talk about C++ &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2011/06/15/introducing-amp.aspx" target="_blank"&gt;AMP&lt;/a&gt;, a new abstraction that allows you run part of your C++ code using the GPU. &lt;/p&gt;  &lt;p&gt;Beside new upcoming technologies we will continue to talk about our current everyday foundations and tools. In the second half of the meeting I am going to talk about some of the reliability mechanisms of Windows 7 &amp;amp; Windows Server 2008 R2, such as Kernel Transaction, and the Windows Restart Manager. I will present how to use these mechanisms using native C++ code as well as from .NET WPF+WCF code.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Please go, &lt;a href="http://vcppamp-dec11.eventbrite.com/" target="_blank"&gt;register&lt;/a&gt; and make sure that you have a place in the next meeting.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Alon.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=938033" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+Server+2008/default.aspx">Windows Server 2008</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/User+Group/default.aspx">User Group</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Parallel/default.aspx">Parallel</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Future/default.aspx">Future</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Build/default.aspx">Build</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_+11/default.aspx">C++ 11</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/AMP/default.aspx">AMP</category></item><item><title>My Omnia 7 Is now 7.5</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/09/30/my-omnia-7-is-now-7-5.aspx</link><pubDate>Fri, 30 Sep 2011 01:35:07 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:908321</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=908321</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=908321</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/09/30/my-omnia-7-is-now-7-5.aspx#comments</comments><description>&lt;p&gt;Microsoft has released the Windows Phone Mango update. It can take a while to get the update. However there is a trick that can let you have the update right away. Follow &lt;a href="http://www.wpcentral.com/force-mango-update-early-through-zune-software?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+wmexperts+%28wpcentral%29" target="_blank"&gt;this&lt;/a&gt; article to get Mango now!, it worked in my case. You don’t need to pull the network cable out. You can disable and re-enable the network connection from the &lt;font color="#ff0000"&gt;Control Panel\Network and Internet\Network Connections&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=908321" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Phone/default.aspx">Phone</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/WP7/default.aspx">WP7</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Update/default.aspx">Update</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Mango/default.aspx">Mango</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/7.5/default.aspx">7.5</category></item><item><title>My Build Event Insights</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/09/20/my-build-event-insights.aspx</link><pubDate>Tue, 20 Sep 2011 20:03:42 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:903449</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=903449</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=903449</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/09/20/my-build-event-insights.aspx#comments</comments><description>&lt;p&gt;You didn&amp;#39;t have to go to &lt;a href="http://www.buildwindows.com/"&gt;//BUILD/&lt;/a&gt; to get the information and knowledge of the new Windows Platform APIs; you could &lt;a href="http://channel9.msdn.com/events/BUILD/BUILD2011"&gt;watch&lt;/a&gt; all the sessions from the comfort of your home, and I encourage you to do so, however attending the conference helps obtaining a perception about the future of Microsoft and especially the future of Windows technologies and the reaction of the developers that attended the conference.&lt;/p&gt;  &lt;p&gt;I didn&amp;#39;t want to post about the conference before I have a clear picture, and believe me the picture was obscured. According to the first day keynote and the discussions on tweeter and the various mailing lists, I got it all wrong; however by digging into the implementation of WinRT, by talking with people from the Platform team and by attending the last day sessions, I got a better and clearer picture. &lt;/p&gt;  &lt;p&gt;So what is Metro Style Application, what is WinRT, and should I learn C++ or HTML &amp;amp; JavaScript?&lt;/p&gt;  &lt;p&gt;Let&amp;#39;s start with the underlying system. Windows Run-Time (WinRT) is a new platform for using and consuming the Windows OS resources. It is a modern native layer on top of Win32 and the Windows Kernel that replaces Win32 APIs and other frameworks like MFC for the native world and many of the .NET classes and technologies for the managed environment.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;WinRT has a new type system, quite similar to the .NET Common Type System (CTS), however it is optimized for native code usage and for cross language calls with .NET, JavaScript and C++ in mind. The type system also provides rich type information that is based on the same metadata schema of .NET, however for native code there is no IL, GC and JIT.&lt;/li&gt;    &lt;li&gt;WinRT is heavily based on COM, however it is not IDL based, and we get all the goodies of a modern Object Oriented based technology such as classes, static functions, methods, properties, delegates, events and inheritance.&lt;/li&gt;    &lt;li&gt;WinRT APIs are either asynchronous for potentially long operations, or synchronous for fast non-blocking functions.&lt;/li&gt;    &lt;li&gt;WinRT provides the installation facilities as well as the environment activation and hosting.&lt;/li&gt;    &lt;li&gt;WinRT is based on components. This enables sharing implementation between languages.&lt;/li&gt;    &lt;li&gt;WinRT provides rich mechanism for inter Metro application communication through Contracts - as a developer you have the Launch Contract, Search Contract, Share Contract and many more. You can provide contract implementation or consume a contract. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Metro is the new client development platform. It is based on WinRT classes. Metro applications are fast, smooth, and safe. Metro application can use only &amp;quot;safe&amp;quot; APIs, which are the WinRT classes&amp;#39; members and a white list of other APIs. For .NET a special client profile is provided that contains only non (potentially) blocking calls and does not contain duplications for APIs provided by WinRT. To use sensitive user information such as location devices or a Web Cam, you need to declare these needed capabilities. Windows will ask the user for permission to run your code and use these capabilities (much like the standard for mobile applications). Metro Apps occupy the whole screen (chrome-less) and have a new life time management. They have to start quickly, they get suspended once they are in the background and background apps get terminated if the system resources are low. Each WinRT application runs as an STA COM component, and if there is a need to answer a new contract request, a new STA instance is lunched. &lt;/p&gt;  &lt;p&gt;&lt;font color="#00ff00"&gt;Now to some of the BIG concerns, what are the consequences of these new Windows mechanisms?&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;If you are a Windows C++ developer&lt;/font&gt;, it means that you get much better tooling and a framework that resembles the .NET development API. You need to learn the XAML concepts and the Metro UI object model. You also need to learn the C++ extensions for WinRT – although if you are familiar with C++/CLI, the extensions are very much the same. If you haven&amp;#39;t upgraded your knowledge to C++ 11, you also need to handle this learning curve. The result is much better productivity, safe code, and fast &amp;amp; fluid user interface. &lt;/p&gt;  &lt;p&gt;C++ is back, as Herb Sutter said in his talk – for fifteen years we didn&amp;#39;t care about performance, but now that we pay for running our code in the cloud, or we target lightweight hardware such as slate devices and we want to preserve power, performance is a big issue again. C++ and WinRT are performance tuned and WinRT ref-count based resource management provides deterministic finalization which means that we don&amp;#39;t hold unneeded resources. &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;If you are a C#/VB developer&lt;/font&gt; and productivity is more important to you than execution speed and low resource consumption, continue to do what you already do. Use the Metro profile with the .NET framework. WinRT provides all the metadata information that is needed to create and call WinRT objects, while .NET provides the GC, JIT, and all other mechanisms that make .NET so easy to use. To call a WinRT component .NET uses the same CCW/CRW mechanism that is used for COM interop, however the borrowed metadata mechanisms plus the new WinRT type system make this interop story much easier and faster. I hear a lot of complaints from .NET developers that WinRT &amp;quot;kills&amp;quot; many .NET technologies, however the exact opposite is the true! WinRT borrowed many of its concepts from .NET, its metadata, properties, delegates &amp;amp; events and others. Metro UI is based on XAML and the Silverlight/WPF object model. It is easier for a .NET developer to develop new metro application compared to a native C++ MFC developer. &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;If you are a web developer&lt;/font&gt;, JavaScript is a first class citizen for developing Metro style application on top of WinRT. You get the WinRT object model, and method names even appear in Camel Casing even though for C#/VB/C++ they appear as Pascal Casing. &lt;/p&gt;  &lt;p&gt;If you are a UI/UX developer, Blend 5 and Visual Studio UI editor are upgraded to support Metro style application. You can also design HTML/CSS using Blend. You get to preserve all your old knowledge and practice while designing with the new Metro style. You also get many predefined UI templates.&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;If you are a Windows developer&lt;/font&gt;, many of the technologies that you know are there. Everything behind the scenes is COM, with major abstraction on top of COM. You can choose the language that you want or the one that you think is better for the job. You can develop C++ based components using native libraries such as boost and consume them from JavaScript or C#. &lt;/p&gt;  &lt;p&gt;There are many new details to dive into now, but we also have the time. We are not even in the beta phase of the system and things will certainly change, but we are starting to see the tip of the iceberg.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=903449" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B002F00_CLI/default.aspx">C++/CLI</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/COM/default.aspx">COM</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/MFC/default.aspx">MFC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/conference/default.aspx">conference</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CPP_2F00_CLI/default.aspx">CPP/CLI</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_+Renaissance/default.aspx">C++ Renaissance</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+8/default.aspx">Windows 8</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/WinRT/default.aspx">WinRT</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Build/default.aspx">Build</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_+11/default.aspx">C++ 11</category></item><item><title>C++ is coming back!</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/09/04/c-is-coming-back.aspx</link><pubDate>Sun, 04 Sep 2011 12:16:22 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:894320</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=894320</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=894320</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/09/04/c-is-coming-back.aspx#comments</comments><description>&lt;p&gt;C++ is coming back, it will be in the focus of the next &lt;a href="http://www.buildwindows.com/" target="_blank"&gt;Microsoft Build event&lt;/a&gt; and also in our next meeting of the Windows Platform Developer User Group. On this Wednesday (the 7th) we will hold a WPDUG meeting in Microsoft’s offices in Ra’anana (Israel). &lt;/p&gt;  &lt;p&gt;Our first session will be about adding realtime and deterministic capabilities to Windows and its impact on the system and the ways to program such a system (all based on addons by a company called &lt;a href="http://www.tenasys.com/"&gt;TenAsys&lt;/a&gt;). The second session will demonstrate useful (and undocumented) debugging tips and tricks in Visual Studio (primarily for native developers).&lt;/p&gt;  &lt;p&gt;In future meetings we will start to dive into the new Windows 8 mechanisms. It is time to join our user group! &lt;/p&gt;  &lt;p&gt;Use this &lt;a href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032491759&amp;amp;Culture=he-IL"&gt;link&lt;/a&gt; to register and review the detailed agenda.&lt;/p&gt;  &lt;p&gt;See you there!&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=894320" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/VC/default.aspx">VC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/User+Group/default.aspx">User Group</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/WPD/default.aspx">WPD</category></item><item><title>Expert Days 2011 - Summary</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/07/20/expert-days-2011-summary.aspx</link><pubDate>Tue, 19 Jul 2011 22:05:04 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:870090</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=870090</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=870090</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/07/20/expert-days-2011-summary.aspx#comments</comments><description>&lt;p&gt;I really enjoyed taking part in the &lt;a href="http://www.e4d.co.il/"&gt;E4D&lt;/a&gt; expert day. The organization, atmosphere and the audience were perfect. I&amp;#39;d like to thank &lt;a href="http://blogs.microsoft.co.il/blogs/vardi/"&gt;Eyal&lt;/a&gt; and &lt;a href="http://www.linkedin.com/in/sarittamir"&gt;Sarit&lt;/a&gt; for the opportunity to deliver three lectures in this event. I&amp;#39;d like also to thank the professional people that came to hear me. I enjoyed the interaction, the hard questions, the comments and feedbacks you have provided. For those of you that took part in one of my seminars, please contact me and request a link to the materials download sites. Please tell your friends about the seminars. If you want to have the full course, or other &lt;a href="http://www.codevalue.net/"&gt;CodeValue&lt;/a&gt; course, take a look at: &lt;a href="http://college.codevalue.net/"&gt;http://college.codevalue.net/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://college.codevalue.net/"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_17E084A0.png" width="148" height="96" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=870090" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/MVP/default.aspx">MVP</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/TECH/default.aspx">TECH</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category></item><item><title>When something become a main stream it is no longer a niche</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/07/02/when-something-become-a-main-stream-it-is-no-longer-a-niche.aspx</link><pubDate>Sat, 02 Jul 2011 09:15:01 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:848403</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=848403</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=848403</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/07/02/when-something-become-a-main-stream-it-is-no-longer-a-niche.aspx#comments</comments><description>&lt;p&gt;Microsoft has &lt;a href="http://www.zdnet.com/blog/microsoft/microsoft-to-retire-refocus-windows-phone-mvp-program/9897" target="_blank"&gt;shut down its Windows Phone MVP program&lt;/a&gt;; they will reopen it as more consumer-focused group. I don&amp;#39;t know all the reasons for that, and I would appreciate if they could rearrange the group without retire all mobile MVPs, but I think that there is something else that this news tells us. Windows Phone is not a niche, it is part of something bigger, and the client/consumer device story is changing. We consume information through our PC, Phone, Slate device, TV, Xbox. All of them are part of our everyday user interface, and in many cases for the same server side application like office 365, or Gmail. &lt;/p&gt;  &lt;p&gt;This is also the sign that if you are a user interface/client side developer, you should not focus on mobile device development, or PC user interface development only. You should target your development skills to be able to develop for all of them. The Microsoft development story provides you the ability to use almost the same tools and language to develop across all devices UI including the PC and Xbox. Apple gives you the same experience for the iPhone and the iPad, Android O/S runs on Phone and Tablet too. &lt;/p&gt;  &lt;p&gt;HTML 5 provides you the ability to develop cross platform for all platforms, and soon also for Windows 8 (but I am quite sure that HTML for Windows 8 will be Microsoft bound development tools and API). &lt;/p&gt;  &lt;p&gt;So focusing on more consumers oriented MVP group is not a bad idea, and I hope that many of the old Windows Phone MVP will be part of this group; after all they have got their MVP for what they are and what they are doing. Of course, it they don’t like the new Windows Phone and the new Windows 8 running on slate device, they can&amp;#39;t promote and evangelist Microsoft, Microsoft will not choose them…&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=848403" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/MVP/default.aspx">MVP</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/OFFTOPIC/default.aspx">OFFTOPIC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/iPad/default.aspx">iPad</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/iPhone/default.aspx">iPhone</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+8/default.aspx">Windows 8</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/WP7/default.aspx">WP7</category></item><item><title>MVP again, and not alone</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/07/01/mvp-again-and-not-alone.aspx</link><pubDate>Fri, 01 Jul 2011 17:06:09 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:848169</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=848169</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=848169</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/07/01/mvp-again-and-not-alone.aspx#comments</comments><description>&lt;p&gt;I have just received a mail telling me that I am continued to be a C++ &lt;a href="http://mvp.support.microsoft.com/" target="_blank"&gt;MVP&lt;/a&gt;, 6 year in a row. I am happy to be C++ MVP. Although I am doing a lot of .NET and C# developing, I am also continue to have C++ project, Win32 and COM and I am doing a lot of interop. I have also taught several C++ classes this year including &lt;a href="http://college.codevalue.net/course/advanced-windows-debugging-techniques" target="_blank"&gt;Advanced Windows Debugging Techniques&lt;/a&gt; and &lt;a href="http://college.codevalue.net/course/windows-concurrent-programming-in-the-multi-core-era" target="_blank"&gt;Windows Concurrent Programming in the Multi-Core Era&lt;/a&gt; with the new concurrent runtime and libraries of VC++ 10. The &lt;a href="http://windows8center.com/" target="_blank"&gt;rumors&lt;/a&gt; say that C++ will play big role in the upcoming Windows 8 and that the &lt;a href="http://www.buildwindows.com/" target="_blank"&gt;Build&lt;/a&gt; event is not just about JS and HTML 5, but also a lot of C++.&lt;/p&gt;  &lt;p&gt;I want to thank the VC++ team for this recognition and also to thank &lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/" target="_blank"&gt;Guy Burstein&lt;/a&gt; for his support.&lt;/p&gt;  &lt;p&gt;As the title said, I am not alone. &lt;a href="http://geekswithblogs.net/JoshReuben/Default.aspx" target="_blank"&gt;Josh Reuben&lt;/a&gt;, a colleague at &lt;a href="http://codevalue.net/" target="_blank"&gt;CodeValue&lt;/a&gt;, one of the most talented and professional person that I know also recognized as an MVP. This is his first time and he earned it by hard work. People, who know Josh, know that he has a list of what he has to read and learn for the coming 2-3 years. When you open one of his computer books you see that the important words and line are marked with yellow marker.&lt;/p&gt;  &lt;p&gt;If you want to meet Josh, come to his &lt;a href="http://www.e4d.co.il/Events/ExpertDays2011/Courses/Details/29" target="_blank"&gt;XNA lecture&lt;/a&gt; at Expert Days next week.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=848169" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/MVP/default.aspx">MVP</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/COM/default.aspx">COM</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category></item><item><title>Fun With XNA</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/06/29/fun-with-xna.aspx</link><pubDate>Tue, 28 Jun 2011 22:06:38 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:847071</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=847071</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=847071</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/06/29/fun-with-xna.aspx#comments</comments><description>&lt;p&gt;I recently played with XNA. There is a game that I have developed many times, on the &lt;a href="http://en.wikipedia.org/wiki/Commodore_64" target="_blank"&gt;Commodore 64&lt;/a&gt; as a kid, on the &lt;a href="http://en.wikipedia.org/wiki/Amiga" target="_blank"&gt;Commodore Amiga&lt;/a&gt;, later on Windows 9X with MFC, after that in .NET and Windows Forms, and now with &lt;a href="http://msdn.microsoft.com/en-us/aa937791" target="_blank"&gt;XNA&lt;/a&gt;. The development experience in XNA was the best, and I can run my game on the phone, on Windows and on my XBOX. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_512DDA7B.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_5EB0251C.png" width="268" height="484" /&gt;&lt;/a&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_2086E49E.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_218BA7F0.png" width="268" height="484" /&gt;&lt;/a&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_529ABCC3.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_35C0FC14.png" width="268" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The goal of the game is to have higher score &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.microsoft.co.il/blogs/alon/wlEmoticon-smile_30AE9898.png" /&gt;. Each player moves only in a specific direction (vertical or horizontal). In each turn a player move the token (S shape) and take a number (replace a number with the token), the value of the number is added to the player score.&lt;/p&gt;  &lt;p&gt;One interesting thing about the game is that I usually lose when I play with it. The game thinking is base on &lt;a href="http://en.wikipedia.org/wiki/Alpha-beta_pruning" target="_blank"&gt;Min-Max with Alpha-Beta pruning&lt;/a&gt; algorithm. The heuristics is very simple: player1 score minus player2 score. The computer/XBox/Phone is thinking while the player is thinking. &lt;/p&gt;  &lt;p&gt;When I win, I think what I did wrong, When I lose, I proud that the algorithm works, but I then I think how come a so simple algorithm can be so smart…&lt;/p&gt;  &lt;p&gt; The only way to win the computer is if you get a board that has a better number setting in your playing direction, how do I know that? because I added an option to play the same game with the opposite direction…&lt;/p&gt;  &lt;p&gt;The game is working and is almost done, but I have more ideas that I want to implement before I will upload it to the Windows 7 Application Store, for example a two players game using push notifications.&lt;/p&gt;  &lt;p&gt;If you familiar with C# and .NET, you just need a good &lt;a href="http://www.e4d.co.il/Events/ExpertDays2011/Courses/Details/29" target="_blank"&gt;kick start&lt;/a&gt; for XNA and you there, and XNA is not just for games, it is the easiest platform to develop 2D and 3D based graphics and animations on top of Windows, Windows Phone and XBOX, and you can &lt;a href="http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1" target="_blank"&gt;host an XNA&lt;/a&gt; Windows in your WPF/WinForm application.&lt;/p&gt;  &lt;p&gt;More information about XNA development can be found on &lt;a href="http://geekswithblogs.net/JoshReuben/archive/2011/06/28/xna-multiplayer-games-and-networking.aspx" target="_blank"&gt;Josh’s blog&lt;/a&gt;, and if you really want to know how, register to &lt;a href="http://www.e4d.co.il/Events/ExpertDays2011/Courses/Details/29" target="_blank"&gt;Josh’s XNA Expert Day Session&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=847071" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/MFC/default.aspx">MFC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/conference/default.aspx">conference</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Phone/default.aspx">Phone</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Fun/default.aspx">Fun</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/XNA/default.aspx">XNA</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CloudValue/default.aspx">CloudValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Amiga/default.aspx">Amiga</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Game/default.aspx">Game</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Expert+Days/default.aspx">Expert Days</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Sums/default.aspx">Sums</category></item><item><title>Tech Ed Atlanta 2011</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/05/18/tech-ed-atlanta-2011.aspx</link><pubDate>Wed, 18 May 2011 15:10:38 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:836249</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=836249</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=836249</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/05/18/tech-ed-atlanta-2011.aspx#comments</comments><description>&lt;p&gt;Now, after &lt;a href="http://northamerica.msteched.com/%5Cspeaker%5Cdetails%5CShy_Cohen?fbid=2ue8cElicUo" target="_blank"&gt;Shy&lt;/a&gt; &amp;amp; &lt;a href="http://mobile.microsoft.com/TechEd/NA/Attendees/312b843c-e566-4bee-9d36-570657cf6793?sid=e1aPd1IqO0W1UBfL6ypMJQ#fbid=2ue8cElicUo" target="_blank"&gt;I&lt;/a&gt; have delivered the &lt;a href="http://northamerica.msteched.com/topic/details/DPR307?fbid=2ue8cElicUo" target="_blank"&gt;Cost Oriented Development&lt;/a&gt; lecture, I can relax and post a little bit about this conference. &lt;a href="http://blogs.microsoft.co.il/blogs/alon/226891_226164677397417_153188588028360_1047748_28682_n1_17BF2DEF.jpg"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:9px 18px 9px 0px;padding-left:0px;padding-right:0px;display:inline;float:left;border-top:0px;border-right:0px;padding-top:0px;" title="226891_226164677397417_153188588028360_1047748_28682_n[1]" border="0" alt="226891_226164677397417_153188588028360_1047748_28682_n[1]" align="left" src="http://blogs.microsoft.co.il/blogs/alon/226891_226164677397417_153188588028360_1047748_28682_n1_thumb_3B0C2294.jpg" width="640" height="478" /&gt;&lt;/a&gt;&lt;a href="http://northamerica.msteched.com/default.aspx"&gt;Tech Ed 2011&lt;/a&gt; is a really BIG conference. The &lt;a href="http://www.gatechcenter.com/offer/ikl1/?gclid=CMj018fi8agCFQmt7QodyWrV-g" target="_blank"&gt;Georgia World Conference Center&lt;/a&gt; is huge, and even thousands of attendees can not fill it. The Expo is twice larger than it was in the last LA PDC and you can see that companies that present here invest a lot. The audience is a mixture of IT professionals and developers. &lt;a href="http://www.cloudvalue.com/" target="_blank"&gt;CloudValue&lt;/a&gt;, the &lt;a href="http://codevalue.net/" target="_blank"&gt;CodeValue&lt;/a&gt; subsidiary company has a booth. We present our new cost online service tracking tool and sign companies to our beta program. We get very good reactions from companies that have already deployed their applications to the Windows Azure platform and others that are in the stage of shifting to the cloud. &lt;/p&gt;    &lt;p&gt;The lecture that Shy and I have delivered also dealt with Cost Orientation. Cost Orientation is a new discipline, also it had to be part of our software development process long before. Since we are entering the cloud era, cost can be managed and is no longer transparent; you know the runtime cost of your application. In our lecture we have shown methods and tool to understand, plan, solve and review cost implications in any stage of the application life cycle. Our main statement is &amp;quot;Not accounting for the cost implications of your architecture design, and implementation will result in lower cost-efficiency&amp;quot;. Besides talking about the methodology, we have also presented Cost Oriented Architectural and Code patterns and best practices.&lt;/p&gt;  &lt;p&gt;If you are here at Tech-Ed Atlanta and wants to know more about Cost Orientation and CloudValue offerings, come to visit us in booth 1050.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=836249" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Teched/default.aspx">Teched</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+Azure/default.aspx">Windows Azure</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/conference/default.aspx">conference</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/TECH/default.aspx">TECH</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Cloudoscope/default.aspx">Cloudoscope</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Cost+Oriented+Development/default.aspx">Cost Oriented Development</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CloudValue/default.aspx">CloudValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Cloud/default.aspx">Cloud</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Tech+Ed+2011/default.aspx">Tech Ed 2011</category></item><item><title>C++ Renaissance: Getting Back The Free Lunch</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/04/16/c-renaissance-getting-back-the-free-lunch.aspx</link><pubDate>Sat, 16 Apr 2011 02:15:34 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:818994</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=818994</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=818994</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/04/16/c-renaissance-getting-back-the-free-lunch.aspx#comments</comments><description>&lt;p&gt;At the beginning of 2005 &lt;a href="http://herbsutter.com/"&gt;Herb Sutter&lt;/a&gt; had an &lt;a href="http://www.gotw.ca/publications/concurrency-ddj.htm"&gt;article&lt;/a&gt; stating that the developer’s free lunch is over. We had an assumption that more transistors in the CPU imply better application execution speed. The CPU executes the code in a sequential manner hence the performance of the CPU-bound code is directly related to CPU frequency. This used to be our “Free Lunch”: an old program runs faster on a new CPU. Using this assumption with modern low power consumption multi-core CPUs is wrong, we might even find that an old program runs slower on a new CPU. Since performance is no longer tied to CPU frequency we need to leverage parallelism. To some extent this is not a new concept, multiprocessing systems exist for years. For example &lt;a href="http://en.wikipedia.org/wiki/Windows_NT"&gt;Windows NT&lt;/a&gt; was designed back in 1989 as a &lt;a href="http://en.wikipedia.org/wiki/Symmetric_multiprocessing"&gt;Symmetric Multiprocessing&lt;/a&gt; Operating System. &lt;a href="http://en.wikipedia.org/wiki/Hyper_threading"&gt;Hyper threading&lt;/a&gt; CPUs exist at least half a decade. But do we get better performance by moving from one-way machine to 16-ways? We need a better abstraction!&lt;/p&gt;  &lt;p&gt;Our software design can be based on multi-threading execution. We can align the number of threads to the number of cores, but does this mean that if we double the cores, we double the performance? Probably not! There are many obstacles that we need to overcome. It is not easy to split a task to many threads. Creating threads is a costly operation. Kernel based context switch implies more overhead. We need to make sure that the number of running thread concurrently will not be more than the number of cores, however if a thread gets blocked we need to free or create another thread to run to utilized the free core. Add to that the fact that systems with many cores have NUMA architecture, which means that allocating and affinity of memory to threads and core can gain more performance. &lt;/p&gt;  &lt;p&gt;Parallelism is hard, instead of inventing the underlying abstraction; we want to use existing well-known ones. In this post we will see how the C++ Concurrency Runtime (&lt;a href="http://msdn.microsoft.com/en-us/library/dd504870.aspx"&gt;ConcRT&lt;/a&gt;) and Parallel Pattern Library (&lt;a href="http://msdn.microsoft.com/en-us/library/dd492418.aspx"&gt;PPL&lt;/a&gt;) provide the needed abstraction and bring us back the free lunch. Using these abstractions we will gain performance from running the same application on many cores. We will also compare the new ConcRT libraries to the .NET Task Parallel Library (&lt;a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx"&gt;TPL&lt;/a&gt;) and see that the concept are quiet similar, however C++ has a better runtime (Resource Manager and &lt;a href="http://msdn.microsoft.com/en-us/library/dd984036.aspx"&gt;Task Scheduler&lt;/a&gt;) that taking NUMA into consideration and can result better performance on such architectures.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;To show that throwing more cores result better performance we will calculate prime numbers in a loop. We want to find the highest prime number that we can in 10 seconds. We will start with one core and do the same algorithm throwing more cores. Since I am using a Core i7 Hyper-threaded enabled machine, we will see some degradation in scalability when we will reach a high number of cores (actually virtual CPUs since it is hyper-threaded). &lt;/p&gt;  &lt;p&gt;Bear in mind that finding the highest prime number is non-linear problem. I.E, finding a 10 digits number will take much more time than finding a 5 digits prime number. So it will be hard to deduce the scalability factor. What we will see is that adding more cores brings back our free lunch!&lt;/p&gt;  &lt;p&gt;To keep contention to the minimum we will use the &lt;a href="http://msdn.microsoft.com/en-us/library/dd492850.aspx" target="_blank"&gt;combinable&amp;lt;T&amp;gt;&lt;/a&gt; class. This class provides a local copy for each thread. In our case each thread will hold its maximum finding and then using the &lt;a href="http://msdn.microsoft.com/en-us/library/dd492446.aspx" target="_blank"&gt;combine()&lt;/a&gt; method, we will pick the maximum number from all the threads. To handle the time limit, we will use the task &lt;a href="http://msdn.microsoft.com/en-us/library/dd492470.aspx" target="_blank"&gt;task_group.cancel()&lt;/a&gt; method to finish the current parallel loop execution. To limit the range of numbers, we will use groups of 8192 numbers in parallel at a time. &lt;/p&gt;  &lt;p&gt;The C++ Code:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div align="left"&gt;   &lt;pre class="code"&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:green;"&gt;// ----------------------------------------------------------------------
// &amp;lt;copyright file=&amp;quot;GettingBackTheFreeLunch.cpp&amp;quot; company=&amp;quot;CodeValue&amp;quot;&amp;gt;
//     Copyright (c) 2011 by CodeValue Ltd. All rights reserved
// &amp;lt;/copyright&amp;gt;
//
// http://codevalue.com
// Licensed under the Educational Community License version 1.0 (http://www.opensource.org/licenses/ecl1)
// This example was written as a demonstration of principles only, &lt;br /&gt;// as part of the Windows Concurrent programming course for C++ developers
//
// ------------------------------------------------------------------------

&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;stdafx.h&amp;quot;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;Windows.h&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;ppl.h&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;concurrent_vector.h&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;iostream&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;functional&amp;gt;

&lt;/span&gt;&lt;span style="color:blue;"&gt;#undef &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;max

&lt;/span&gt;&lt;span style="color:blue;"&gt;using namespace &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;std;
&lt;/span&gt;&lt;span style="color:blue;"&gt;using namespace &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;Concurrency;

ULONGLONG FindLargestPrimeNumberInTime(DWORD concurrencyLevel, DWORD timeInterval);

&lt;/span&gt;&lt;span style="color:blue;"&gt;int &lt;/span&gt;&lt;span style="color:white;"&gt;_tmain(&lt;/span&gt;&lt;span style="color:blue;"&gt;int &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;argc, _TCHAR* argv[])
{
    SYSTEM_INFO systemInformation;
    ::GetSystemInfo(&amp;amp;systemInformation);

    wcout &amp;lt;&amp;lt; L&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;Number of logical processor: &amp;quot; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;&amp;lt;&amp;lt; systemInformation.dwNumberOfProcessors &amp;lt;&amp;lt; endl;

    &lt;/span&gt;&lt;span style="color:blue;"&gt;for &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;(DWORD concurrencyLevel = 1; concurrencyLevel &amp;lt;= systemInformation.dwNumberOfProcessors; ++concurrencyLevel)
    {
        DWORD timeInterval = 1000 * 10;
        ULONGLONG largetPrimeNumber = FindLargestPrimeNumberInTime(concurrencyLevel, timeInterval);
        wcout &amp;lt;&amp;lt; L&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;Result: &amp;quot; &lt;/span&gt;&lt;span style="color:white;"&gt;&amp;lt;&amp;lt; largetPrimeNumber &amp;lt;&amp;lt; L&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot; in &amp;quot; &lt;/span&gt;&lt;span style="color:white;"&gt;&amp;lt;&amp;lt; timeInterval/1000 &amp;lt;&amp;lt; L&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot; seconds using &amp;quot; &lt;/span&gt;&lt;span style="color:white;"&gt;&amp;lt;&amp;lt;  concurrencyLevel &amp;lt;&amp;lt; L&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot; Logical Processors&amp;quot; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;&amp;lt;&amp;lt; endl;
    }
    &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;0;
}

&lt;/span&gt;&lt;span style="color:blue;"&gt;bool &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;IsPrime(ULONGLONG number, DWORD tickCountLimit)
{
    &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;((number &amp;amp; 1) == 0)
        &lt;/span&gt;&lt;span style="color:blue;"&gt;return false&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;

    ULONGLONG limit = &lt;/span&gt;&lt;span style="color:blue;"&gt;static_cast&lt;/span&gt;&lt;span style="color:white;"&gt;&amp;lt;ULONGLONG&amp;gt;(sqrt(&lt;/span&gt;&lt;span style="color:blue;"&gt;static_cast&lt;/span&gt;&lt;span style="color:white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:blue;"&gt;double&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;&amp;gt;(number)));

    &lt;/span&gt;&lt;span style="color:blue;"&gt;for &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;(ULONGLONG n = 3; n &amp;lt;= limit; n += 2)
    {
        &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;( (number % n == 0) || (::GetTickCount() &amp;gt; tickCountLimit))
            &lt;/span&gt;&lt;span style="color:blue;"&gt;return false&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;
    }
    &lt;/span&gt;&lt;span style="color:blue;"&gt;return true&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;
}

ULONGLONG FindLargestPrimeNumberInTime(DWORD concurrencyLevel, DWORD timeInterval)
{
    ULONGLONG result = 3;

    SchedulerPolicy policy;
    policy.SetConcurrencyLimits(concurrencyLevel, concurrencyLevel);
    CurrentScheduler::Create(policy);

    task_group taskGroup;
    
    taskGroup.run_and_wait([&amp;amp;]
    {
        DWORD dueTime = ::GetTickCount() + timeInterval;
        combinable&amp;lt;ULONGLONG&amp;gt; maxPrime([]()-&amp;gt;ULONGLONG { &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;3; });
        ULONGLONG slice = 8192;

        &lt;/span&gt;&lt;span style="color:blue;"&gt;for &lt;/span&gt;&lt;span style="color:white;"&gt;(ULONGLONG range = 3; range &amp;lt; ~&lt;/span&gt;&lt;span style="color:blue;"&gt;static_cast&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;&amp;lt;ULONGLONG&amp;gt;(0); range += slice)
        {

            parallel_for&amp;lt;ULONGLONG&amp;gt;(range,range + slice, 1, [&amp;amp;](ULONGLONG n) 
            {
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;(IsPrime(n, dueTime))
                    maxPrime.local() = max(maxPrime.local(), n);
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;(::GetTickCount() &amp;gt; dueTime)
                    taskGroup.cancel();
            });
            result = maxPrime.combine(max&amp;lt;ULONGLONG&amp;gt;);
        }
    });

    &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="color:white;"&gt;&lt;font size="3" face="Consolas"&gt;result;
}&lt;/font&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The result is:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ffffff" size="3" face="Consolas"&gt;Number of logical processor: 8
    &lt;br /&gt;Result: 16252919 in 10 seconds using 1 Logical Processors

    &lt;br /&gt;Result: 19365887 in 10 seconds using 2 Logical Processors

    &lt;br /&gt;Result: 23945203 in 10 seconds using 3 Logical Processors

    &lt;br /&gt;Result: 26845127 in 10 seconds using 4 Logical Processors

    &lt;br /&gt;Result: 29343719 in 10 seconds using 5 Logical Processors

    &lt;br /&gt;Result: 31547357 in 10 seconds using 6 Logical Processors

    &lt;br /&gt;Result: 33079289 in 10 seconds using 7 Logical Processors

    &lt;br /&gt;Result: 26673149 in 10 seconds using 8 Logical Processors

    &lt;br /&gt;Press any key to continue . . .&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;To show the C# free lunch and to compare the results, I implement the same program using .NET TPL. Instead of combinable, the &lt;a href="http://archive.msdn.microsoft.com/ParExtSamples/Release/ProjectReleases.aspx?ReleaseId=4179" target="_blank"&gt;.NET parallel programing sample pack&lt;/a&gt; provides the ReductionVariable class. To stop the loop I use the loopState loop controlling mechanism. To control parallelism I use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.paralleloptions.maxdegreeofparallelism.aspx" target="_blank"&gt;ParallelOptions.MaxDegreeOfParallelism&lt;/a&gt;&amp;#160; property:&amp;#160; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&lt;font size="3" face="Consolas"&gt;using &lt;/font&gt;&lt;/span&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;System;
&lt;/span&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;System.Threading;
&lt;/span&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;System.Threading.Tasks;

&lt;/span&gt;&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;GettingBackTheFreeLunch
{
    &lt;/span&gt;&lt;span style="color:blue;"&gt;class &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="color:#2b91af;"&gt;&lt;font size="3" face="Consolas"&gt;Program
    &lt;/font&gt;&lt;/span&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;{
        &lt;/span&gt;&lt;span style="color:blue;"&gt;static void &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;Main()
        {
            &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;&lt;span style="color:white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;Number of logical processor: {0}&amp;quot;&lt;/span&gt;&lt;span style="color:white;"&gt;, &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.ProcessorCount);

            &lt;/span&gt;&lt;span style="color:blue;"&gt;for &lt;/span&gt;&lt;span style="color:white;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;int &lt;/span&gt;&lt;span style="color:white;"&gt;concurrencyLevel = 1; concurrencyLevel &amp;lt;= &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.ProcessorCount; ++concurrencyLevel)
            {
                &lt;/span&gt;&lt;span style="color:blue;"&gt;const int &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;timeInterval = 1000 * 10;
                &lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;largetPrimeNumber = FindLargestPrimeNumberInTime(concurrencyLevel, timeInterval);
                &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;&lt;span style="color:white;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;Result: {0} in {1} seconds using {2} logical processors&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;,
                                  largetPrimeNumber, timeInterval / 1000, concurrencyLevel);
            }
        }

        &lt;/span&gt;&lt;span style="color:blue;"&gt;static bool &lt;/span&gt;&lt;span style="color:white;"&gt;IsPrime(&lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;span style="color:white;"&gt;number, &lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;tickCountLimit)
        {
            &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;((number &amp;amp; 1) == 0)
                &lt;/span&gt;&lt;span style="color:blue;"&gt;return false&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;

            &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;&lt;span style="color:white;"&gt;limit = &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Math&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.Sqrt(number);

            &lt;/span&gt;&lt;span style="color:blue;"&gt;for &lt;/span&gt;&lt;span style="color:white;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;n = 3; n &amp;lt;= limit; n += 2)
            {
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;span style="color:white;"&gt;((number % n == 0) || (&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.TickCount &amp;gt; tickCountLimit))
                    &lt;/span&gt;&lt;span style="color:blue;"&gt;return false&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;
            }
            &lt;/span&gt;&lt;span style="color:blue;"&gt;return true&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;
        }


        &lt;/span&gt;&lt;span style="color:blue;"&gt;private static long &lt;/span&gt;&lt;span style="color:white;"&gt;FindLargestPrimeNumberInTime(&lt;/span&gt;&lt;span style="color:blue;"&gt;int &lt;/span&gt;&lt;span style="color:white;"&gt;concurrencyLevel, &lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;timeInterval)
        {
            &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;&lt;span style="color:white;"&gt;parallelOption = &lt;/span&gt;&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="color:#2b91af;"&gt;&lt;font size="3" face="Consolas"&gt;ParallelOptions
                                     &lt;/font&gt;&lt;/span&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;{
                                         MaxDegreeOfParallelism = concurrencyLevel
                                     };
            
            &lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;span style="color:white;"&gt;dueTime = &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.TickCount + timeInterval;

            &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;&lt;span style="color:white;"&gt;maxPrime = &lt;/span&gt;&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ReductionVariable&lt;/span&gt;&lt;span style="color:white;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:blue;"&gt;long&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;&amp;gt;(() =&amp;gt; 3);

            &lt;/span&gt;&lt;span style="color:blue;"&gt;const long &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;slice = 8192;

            &lt;/span&gt;&lt;span style="color:blue;"&gt;for &lt;/span&gt;&lt;span style="color:white;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;span style="color:white;"&gt;range = 3; range &amp;lt; &lt;/span&gt;&lt;span style="color:blue;"&gt;long&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.MaxValue; range += slice)
            {
                &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Parallel&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.For(range, range + slice,
                             parallelOption, (n, loopState) =&amp;gt;
                                                 {
                                                     &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;(loopState.IsStopped)
                                                         &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;

                                                     &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;(IsPrime(n, dueTime))
                                                         maxPrime.Value =
                                                             &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Math&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.Max(maxPrime.Value, n);

                                                     &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;span style="color:white;"&gt;(&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.TickCount &amp;gt; dueTime)
                                                         loopState.Stop();
                                                 });


                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;&lt;span style="color:white;"&gt;(&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.TickCount &amp;gt; dueTime)
                    &lt;/span&gt;&lt;span style="color:blue;"&gt;break&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;;
            }
            &lt;/span&gt;&lt;span style="color:blue;"&gt;long &lt;/span&gt;&lt;span style="color:white;"&gt;result = maxPrime.Reduce(&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Math&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:white;"&gt;.Max);
            &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="color:white;"&gt;&lt;font size="3" face="Consolas"&gt;result;
        }
    }
}&lt;/font&gt;
&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The result of the C# code is:&lt;/p&gt;

&lt;p&gt;&lt;font color="#ffffff" size="3" face="Consolas"&gt;Number of logical processor: 8
    &lt;br /&gt;Result: 7946903 in 10 seconds using 1 logical processors

    &lt;br /&gt;Result: 12932119 in 10 seconds using 2 logical processors

    &lt;br /&gt;Result: 16153307 in 10 seconds using 3 logical processors

    &lt;br /&gt;Result: 19601821 in 10 seconds using 4 logical processors

    &lt;br /&gt;Result: 21543757 in 10 seconds using 5 logical processors

    &lt;br /&gt;Result: 23133361 in 10 seconds using 6 logical processors

    &lt;br /&gt;Result: 24362383 in 10 seconds using 7 logical processors

    &lt;br /&gt;Result: 25337269 in 10 seconds using 8 logical processors

    &lt;br /&gt;Press any key to continue . . .&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ffffff" size="3" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The C++ code is a little bit faster, it is hard to tell how much faster due to the non-linearity of the problem. We also need to check it on a real multi-core NUMA based server to have a better comparison between the C++ and the C# code. The nice thing about the C# and the C++ implementation is that we have frameworks that can bring us back the free lunch. &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_350C16EC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_530A24E0.png" width="484" height="292" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=818994" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2300_+4.0/default.aspx">C# 4.0</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Task+Scheduler/default.aspx">Task Scheduler</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Parallel/default.aspx">Parallel</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_+Renaissance/default.aspx">C++ Renaissance</category></item><item><title>Nostalgic Or Reality: The Comeback of Commodore</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/04/09/nostalgic-or-reality-the-comeback-of-commodore.aspx</link><pubDate>Sat, 09 Apr 2011 01:49:17 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:817169</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=817169</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=817169</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/04/09/nostalgic-or-reality-the-comeback-of-commodore.aspx#comments</comments><description>&lt;p&gt;&lt;img border="0" alt="" src="http://www.commodoreusa.net/j/CommodoreHeader64.png" width="640" height="72" /&gt;&lt;/p&gt;  &lt;p&gt;My first personal computer was &lt;a href="http://en.wikipedia.org/wiki/Commodore_VIC-20" target="_blank"&gt;Commodore VIC-20&lt;/a&gt;, or as a geek I should say my first love. With 5KB of RAM (3.5KB for the user) I had to learn Assembly to do a &lt;a href="http://en.wikipedia.org/wiki/Commodore_VIC-20"&gt;&lt;img style="margin:8px 19px 9px 0px;display:inline;float:left;" title="" alt="The Old VIC-20" align="left" src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/39/CBMVIC20P8.jpg/250px-CBMVIC20P8.jpg" width="250" height="171" /&gt;&lt;/a&gt;serious game programming. These were the happy 80’s, the 8-bit computer era. From &lt;a href="http://en.wikipedia.org/wiki/Commodore_VIC-20" target="_blank"&gt;VIC-20&lt;/a&gt; I moved to the &lt;a href="http://en.wikipedia.org/wiki/Commodore_64" target="_blank"&gt;Commodore 64&lt;/a&gt; and then to the &lt;a href="http://en.wikipedia.org/wiki/Commodore_128" target="_blank"&gt;Commodore 128&lt;/a&gt; (My first dual CPU machine &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.microsoft.co.il/blogs/alon/wlEmoticon-smile_511D8F25.png" /&gt;). In My final electronic project at high-school I built an electrical circuit based on &lt;a href="http://en.wikipedia.org/wiki/A2D" target="_blank"&gt;Analog to Digital converter&lt;/a&gt; chip. I developed a Sound Sampling application (using Assembly language) that was able to record 12 seconds of voice filling the 2 64KB banks of the &lt;a href="http://en.wikipedia.org/wiki/Commodore_128" target="_blank"&gt;Commodore 128&lt;/a&gt; memory (It was before the days that you could connect a Microphone to a PC). My next computer was the amazing &lt;a href="http://en.wikipedia.org/wiki/Commodore_Amiga_500" target="_blank"&gt;Commodore Amiga 500&lt;/a&gt;. Amiga was a revolution. The first time I turned it on, I had to go to the manual and read how to use the mouse and how to open and close Windows. Programming the Amiga was a totally different story comparing to the Commodore 64/128. The Amiga had a real multi-tasking &lt;a href="http://en.wikipedia.org/wiki/Amiga_OS" target="_blank"&gt;OS&lt;/a&gt;, with advanced libraries for graphics, sound, file-system and multi-tasking. I’ve learn C/C++ and system programming using the Amiga. When I compiled code, I had to switch the compiler diskette and the target diskette several times. To make my life easier I had to buy another 3.5 floppy disk. Later came my first 20MB hard disk and then I bought the &lt;a href="http://en.wikipedia.org/wiki/Amiga_3000" target="_blank"&gt;Amiga 3000&lt;/a&gt;. I also upgrade my &lt;a href="http://en.wikipedia.org/wiki/Amiga_3000" target="_blank"&gt;Amiga 3000&lt;/a&gt; to the extreme &lt;a href="http://en.wikipedia.org/wiki/Motorola_68060" target="_blank"&gt;Motorola 68060&lt;/a&gt; processor. I ran &lt;a href="http://en.wikipedia.org/wiki/NetBSD" target="_blank"&gt;NetBSD&lt;/a&gt; on the &lt;a href="http://en.wikipedia.org/wiki/Amiga_3000" target="_blank"&gt;Amiga 3000&lt;/a&gt; and also &lt;a href="http://en.wikipedia.org/wiki/Mac_OS" target="_blank"&gt;Mac OS&lt;/a&gt; using &lt;a href="http://en.wikipedia.org/wiki/Emulation_on_the_Amiga" target="_blank"&gt;emulation&lt;/a&gt;. To do my university exercises I used either the &lt;a href="http://en.wikipedia.org/wiki/NetBSD" target="_blank"&gt;NetBSD&lt;/a&gt; (for Unix based courses) and a &lt;a href="http://en.wikipedia.org/wiki/Emulation_on_the_Amiga" target="_blank"&gt;PC emulation&lt;/a&gt; (PC-Task). &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;img title="" border="0" alt="The new VIC-20 Pro" src="http://www.commodoreusa.net/j/SilverVicPro2.png" /&gt;&lt;/p&gt;  &lt;p&gt;Now Commodore is &lt;a href="http://www.commodoreusa.net/CUSA_Home.aspx" target="_blank"&gt;coming back&lt;/a&gt;, what does this mean? &lt;/p&gt;  &lt;p&gt;To my understanding it means a new set of machines targeting the enthusiastic home audience with Commodore look &amp;amp; feel. It also should mean an emphasize in graphics, productivity and creativity. The new Commodore family is based on Intel CPUs, running &lt;a href="http://en.wikipedia.org/wiki/Ubuntu_(operating_system)" target="_blank"&gt;Ubuntu&lt;/a&gt; 10.04 LTS. According to the site a &lt;a href="http://www.commodoreusa.net/CUSA_OS.aspx" target="_blank"&gt;Commodore OS 1.0&lt;/a&gt;, along with emulation functionality and classic game package, will be mailed in the future. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.commodoreusa.net/CUSA_OS.aspx" target="_blank"&gt;Commodore OS&lt;/a&gt; 1.0 is a &lt;a href="http://en.wikipedia.org/wiki/Linux" target="_blank"&gt;Linux&lt;/a&gt; based distribution just like Apple &lt;a href="http://en.wikipedia.org/wiki/Mac_OS_X" target="_blank"&gt;Mac OS X&lt;/a&gt; (&amp;amp; &lt;a href="http://en.wikipedia.org/wiki/IOS_(Apple)" target="_blank"&gt;iOS&lt;/a&gt;)&amp;#160; is based on &lt;a href="http://en.wikipedia.org/wiki/Darwin_(operating_system)" target="_blank"&gt;Darwin&lt;/a&gt; (&lt;a href="http://en.wikipedia.org/wiki/Unix" target="_blank"&gt;Unix&lt;/a&gt;-like OS) and &lt;a href="http://en.wikipedia.org/wiki/Android_(operating_system)" target="_blank"&gt;Google Android&lt;/a&gt; (modified &lt;a href="http://en.wikipedia.org/wiki/Linux" target="_blank"&gt;Linux&lt;/a&gt; Kernel). They did not take the old &lt;a href="http://en.wikipedia.org/wiki/Amiga_OS" target="_blank"&gt;Amiga OS&lt;/a&gt; and upgrade it to be a more modern OS. It means that currently the new Commodore Company is mostly branding &amp;amp; marketing. Maybe we will see some extension to the underlined &lt;a href="http://en.wikipedia.org/wiki/Linux" target="_blank"&gt;Linux&lt;/a&gt; as we see in the case of &lt;a href="http://en.wikipedia.org/wiki/IOS_(Apple)" target="_blank"&gt;iOS&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/IOS_(Apple)" target="_blank"&gt;Android&lt;/a&gt;. They say that old Commodore applications will run, probably by using existing Commodore/&lt;a href="http://en.wikipedia.org/wiki/Amiga_emulation" target="_blank"&gt;Amiga emulation&lt;/a&gt; software. I might be able to run again (on a real machine) some of the games I developed that can still be &lt;a href="http://ftp.sunet.se/pub/aminet/game/think/matix.readme" target="_blank"&gt;found&lt;/a&gt; on the &lt;a href="http://ftp.sunet.se/pub/aminet/game/think/" target="_blank"&gt;web&lt;/a&gt;. I wonder if I can get a dollar for each download from a new Commodore marketplace.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;This is another company that plays in the current changing market, an interesting times, like it used to be back in the 80’s.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=817169" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/TECH/default.aspx">TECH</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/OFFTOPIC/default.aspx">OFFTOPIC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Amiga/default.aspx">Amiga</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Commodore/default.aspx">Commodore</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Linux/default.aspx">Linux</category></item><item><title>C++ Renaissance: The Asynchronous Agents Library</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/04/02/c-renaissance-the-asynchronous-agents-library.aspx</link><pubDate>Fri, 01 Apr 2011 23:40:40 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:815762</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=815762</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=815762</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/04/02/c-renaissance-the-asynchronous-agents-library.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2010 brings back the power of C++. The new language capabilities and optimized STL libraries, the developers productivity as well as the resulting executable performance are much higher. In this post I’d like to present one of the abilities of the ConcRT Asynchronous Agents Library. Agent is based on the &lt;a href="http://en.wikipedia.org/wiki/Actor_model#Fundamental_concepts" target="_blank"&gt;Actor Model&lt;/a&gt; and is one of the building block of a Concurrent Dataflow Network. The idea behind the Asynchronous Agent Library is that you build a network from agents and message blocks. Messages are sent from agent and blocks to other agents and . The ConcRT scheduler is responsible for dispatching virtual processors (threads) to agents and message blocks:&lt;/p&gt;  &lt;p&gt;• An Agent is an asynchronous object that communicates through message passing&lt;/p&gt;  &lt;p&gt;• Message Blocks participate in message-passing which transports from source to target&lt;/p&gt;  &lt;p&gt;• Message encapsulates the state that is transferred between message blocks&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/Agents-programming-model_0765FD6A.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="Agents programming model" border="0" alt="Agents programming model" src="http://blogs.microsoft.co.il/blogs/alon/Agents-programming-model_thumb_017B3404.png" width="644" height="404" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#00ff00" face="Microsoft Sans Serif"&gt;This screen shot is taken from a new C++/WIn32 Concurrent Course of &lt;a href="http://codevalue.net/" target="_blank"&gt;CodeValue&lt;/a&gt;&lt;/font&gt;&lt;font color="#00ff00" face="Microsoft Sans Serif"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Parallelism is achieved by dividing processing tasks into discrete agents. Each agent has a single, well-defined task. Each agent operates on a dedicated memory buffer. Underline the runtime uses lightweight tasks to dispatch messages to agents. You don’t need to synchronize anything. You just need to identify your agents, and the memory buffers that build the network. In this post I want to focus on the &lt;a href="http://msdn.microsoft.com/en-us/library/dd504833.aspx" target="_blank"&gt;Memory Blocks&lt;/a&gt; (Buffers). Usually memory blocks are like queues. They receive and contain messages. However unlike an ordinary queue, they can have special characters and they serves as message dispatchers. &lt;/p&gt;  &lt;p&gt;The library defines tow important interfaces (abstract struct in C++): the &lt;a href="http://msdn.microsoft.com/en-us/library/dd470870.aspx" target="_blank"&gt;ISource&lt;/a&gt; &amp;amp; the &lt;a href="http://msdn.microsoft.com/en-us/library/dd492505.aspx" target="_blank"&gt;ITarget&lt;/a&gt;. Memory Blocks implement these interfaces to enable messages propagation.&amp;#160; There are many predefine Message Blocks, and you can even define &lt;a href="http://msdn.microsoft.com/en-us/library/dd997690.aspx" target="_blank"&gt;your own&lt;/a&gt;. The &lt;a href="http://msdn.microsoft.com/en-us/concurrency/" target="_blank"&gt;Technical Computing&lt;/a&gt; team that is responsible for ConcRT among many other interesting things has released a &lt;a href="http://archive.msdn.microsoft.com/concrtextras/Release/ProjectReleases.aspx?ReleaseId=5189" target="_blank"&gt;Sample Pack&lt;/a&gt; that you can download and use. The sample pack is like CTP and contains extra features including more predefined Message Blocks.&lt;/p&gt;  &lt;p&gt;The following table provides some information about the various Message Blocks (include the ones that are in the Sample Pack &lt;font color="#00ff00"&gt;&lt;strong&gt;&lt;sup&gt;sp&lt;/sup&gt;&lt;/strong&gt;&lt;/font&gt;):&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_5D925CA9.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_7AB804B3.png" width="644" height="414" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The simplest Message Block is the &lt;a href="http://msdn.microsoft.com/en-us/library/dd492602.aspx" target="_blank"&gt;unbounded_buffer&lt;/a&gt;, It can be connected to many sources, holds many messages and can dispatch those messages to many targets. The &lt;a href="http://msdn.microsoft.com/en-us/library/dd492533.aspx" target="_blank"&gt;overwite_buffer&lt;/a&gt; can do the same but stores only the last message it has received. &lt;a href="http://msdn.microsoft.com/en-us/library/dd492468.aspx" target="_blank"&gt;Timer&lt;/a&gt; is a source that sends message when a period of time is elapsed. To send a message to a buffer we use the global &lt;a href="http://msdn.microsoft.com/en-us/library/dd504867.aspx" target="_blank"&gt;send&lt;/a&gt; function. To receive a message from a buffer we you, yes you are correct, the &lt;a href="http://msdn.microsoft.com/en-us/library/dd492823.aspx" target="_blank"&gt;receive&lt;/a&gt; function. We can use &lt;a href="http://msdn.microsoft.com/en-us/library/dd504910.aspx" target="_blank"&gt;asend&lt;/a&gt; to asynchronously send a message and &lt;a href="http://msdn.microsoft.com/en-us/library/dd470874.aspx" target="_blank"&gt;try_receive&lt;/a&gt; if we don’t want a blocking wait for a message. &lt;/p&gt;  &lt;p&gt;With all this knowledge, lets create a Message Block Network that solves a logic circuit of &lt;a href="http://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder" target="_blank"&gt;Full-Adder&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_6047EBCF.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_19EA85BA.png" width="644" height="292" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We are going to use the join_transform Message Block that is part of the Sample Pack. the join_transform is a combination of the &lt;a href="http://msdn.microsoft.com/en-us/library/dd470899.aspx" target="_blank"&gt;join&lt;/a&gt; &amp;amp; &lt;a href="http://msdn.microsoft.com/en-us/library/dd492812.aspx" target="_blank"&gt;transformer&lt;/a&gt; message blocks. It receives messages from&amp;#160; many sources and combine them to one output by applying your transform function (can be Lambda function). We will have three functions for And, Xor and Or. We will use the overwite_buffer for our inputs (A, B, Cin) and we use unbounded_buffer as a connector for outputs that have more then one target. &lt;/p&gt;  &lt;p&gt;To have better abstraction we are going to use typedefs . &lt;/p&gt;  &lt;p&gt;this is the code:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:green;"&gt;// ----------------------------------------------------------------------
// &amp;lt;copyright file=&amp;quot;DataflowLogicCircuit.cpp&amp;quot; company=&amp;quot;CodeValue&amp;quot;&amp;gt;
//     Copyright (c) 2011 by CodeValue Ltd. All rights reserved
// &amp;lt;/copyright&amp;gt;
//
// http://codevalue.com
// Licensed under the Educational Community License version 1.0 (http://www.opensource.org/licenses/ecl1)
// This example was written as a demonstration of principles only
//
// ------------------------------------------------------------------------

// DataflowLogicCircuit.cpp 
// Implementing Full-Adder
// By Alon Fliess

&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;stdafx.h&amp;quot;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;agents.h&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;lt;iostream&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;#include &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font size="3"&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;agents_extras.h&amp;quot;

&lt;/span&gt;&lt;span style="color:blue;"&gt;using namespace &lt;/span&gt;std;
&lt;span style="color:blue;"&gt;using namespace &lt;/span&gt;Concurrency;
&lt;span style="color:blue;"&gt;using namespace &lt;/span&gt;samples;


&lt;span style="color:blue;"&gt;int &lt;/span&gt;_tmain(&lt;span style="color:blue;"&gt;int &lt;/span&gt;argc, _TCHAR* argv[])
{

    &lt;span style="color:blue;"&gt;auto &lt;/span&gt;and = [](vector&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt; input) -&amp;gt; &lt;span style="color:blue;"&gt;bool &lt;/span&gt;{&lt;span style="color:blue;"&gt;return &lt;/span&gt;input[0] &amp;amp;&amp;amp; input[1]; };
    &lt;span style="color:blue;"&gt;auto &lt;/span&gt;or = [](vector&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt; input) -&amp;gt; &lt;span style="color:blue;"&gt;bool &lt;/span&gt;{&lt;span style="color:blue;"&gt;return &lt;/span&gt;input[0] || input[1]; };
    &lt;span style="color:blue;"&gt;auto &lt;/span&gt;xor = [](vector&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt; input) -&amp;gt; &lt;span style="color:blue;"&gt;bool &lt;/span&gt;{&lt;span style="color:blue;"&gt;return &lt;/span&gt;input[0] ^ input[1]; };
    
    &lt;span style="color:blue;"&gt;typedef &lt;/span&gt;overwrite_buffer&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt; Switch;
    &lt;span style="color:blue;"&gt;typedef &lt;/span&gt;join_transform&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;, &lt;span style="color:blue;"&gt;bool&lt;/span&gt;,greedy&amp;gt; gate;


    Switch A,B,Cin;
    gate x1(2, xor);
    overwrite_buffer&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt; x1Output;
    x1.link_target(&amp;amp;x1Output);

    gate x2(2, xor);
    gate a1(2, and);
    gate a2(2, and);
    gate o1(2, or);    
    
    A.link_target(&amp;amp;x1);
    A.link_target(&amp;amp;a2);

    B.link_target(&amp;amp;x1);
    B.link_target(&amp;amp;a2);

    Cin.link_target(&amp;amp;x2);
    Cin.link_target(&amp;amp;a1);

    x1Output.link_target(&amp;amp;x2);
    x1Output.link_target(&amp;amp;a1);

    a1.link_target(&amp;amp;o1);
    a2.link_target(&amp;amp;o1);


    &lt;span style="color:blue;"&gt;for &lt;/span&gt;(&lt;span style="color:blue;"&gt;int &lt;/span&gt;a = 0; a &amp;lt;= 1; ++a)
    {
        &lt;span style="color:blue;"&gt;for &lt;/span&gt;(&lt;span style="color:blue;"&gt;int &lt;/span&gt;b = 0; b &amp;lt;= 1; ++b)
        {
            &lt;span style="color:blue;"&gt;for &lt;/span&gt;(&lt;span style="color:blue;"&gt;int &lt;/span&gt;cin = 0; cin &amp;lt;=1; ++cin)
            {
                send(&amp;amp;A, a != 0);
                send(&amp;amp;B, b != 0);
                send(&amp;amp;Cin, cin != 0);

                wcout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; L&lt;span style="color:#a31515;"&gt;&amp;quot; + &amp;quot; &lt;/span&gt;&amp;lt;&amp;lt; b &amp;lt;&amp;lt; L&lt;span style="color:#a31515;"&gt;&amp;quot; + &amp;quot; &lt;/span&gt;&amp;lt;&amp;lt; cin &amp;lt;&amp;lt; 
                    L&lt;span style="color:#a31515;"&gt;&amp;quot; = &amp;quot; &lt;/span&gt;&amp;lt;&amp;lt; receive(&amp;amp;x2) &amp;lt;&amp;lt; L&lt;span style="color:#a31515;"&gt;&amp;quot; (&amp;quot; &lt;/span&gt;&amp;lt;&amp;lt; receive(&amp;amp;o1) &amp;lt;&amp;lt; L&lt;span style="color:#a31515;"&gt;&amp;quot;)&amp;quot; &lt;/span&gt;&amp;lt;&amp;lt; endl;
            }
        }
    }
    
    &lt;span style="color:blue;"&gt;return &lt;/span&gt;0;
}&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


&lt;p&gt;The result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/image_02039E94.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/alon/image_thumb_18E27010.png" width="244" height="180" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If you are a C++ developer and find this post useful please comment about that.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=815762" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/VC/default.aspx">VC</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Win32/default.aspx">Win32</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/VS+2010/default.aspx">VS 2010</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category></item><item><title>C# - Copying a structure to byte array as is, and back</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/03/16/c-copying-a-structure-to-byte-array-as-is-and-back.aspx</link><pubDate>Wed, 16 Mar 2011 17:08:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:806963</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=806963</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=806963</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/03/16/c-copying-a-structure-to-byte-array-as-is-and-back.aspx#comments</comments><description>&lt;p&gt;A customer asked me today how he can serialize a structure to a byte array for sending to hardware controller. The controller requires that the structure will be sent as is, with no padding or packing. As long as he sure (we dealing with unsafe code) that the data is correct and the size if fine, he can do the following:&lt;/p&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;System;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;System.Collections.Generic;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;System.Linq;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;System.Net.Sockets;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;System.Text;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;System.Runtime.InteropServices;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;namespace&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;ConsoleApplication20&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;StructLayout&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;(&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;LayoutKind&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;.Sequential,&amp;nbsp;Pack&amp;nbsp;=&amp;nbsp;1)]&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;internal&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;struct&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;MyStruct&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;public&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;byte&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;c;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;public&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;int&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;a;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;public&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;ushort&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;b;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;class&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;Program&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;static&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;unsafe&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;void&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;Main(&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;string&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;[]&amp;nbsp;args)&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:blue;"&gt;var&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;s&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;new&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;MyStruct&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;{&amp;nbsp;c&amp;nbsp;=&amp;nbsp;1,&amp;nbsp;a&amp;nbsp;=&amp;nbsp;7,&amp;nbsp;b&amp;nbsp;=&amp;nbsp;15&amp;nbsp;};&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:blue;"&gt;int&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;length&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;.SizeOf(s);&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:green;"&gt;//&amp;nbsp;or&amp;nbsp;this&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:blue;"&gt;int&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;size&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;sizeof&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;(&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;MyStruct&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;);&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:blue;"&gt;var&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;b&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;new&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;byte&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;[size];&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;.Copy(&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;new&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;IntPtr&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;(&amp;amp;s),&amp;nbsp;b,&amp;nbsp;0,&amp;nbsp;size);&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:green;"&gt;//And&amp;nbsp;back...&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:blue;"&gt;var&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;r&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;new&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;MyStruct&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;();&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;font size="2"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&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-FAMILY:Consolas;COLOR:#2b91af;"&gt;Marshal&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;.Copy(b,&amp;nbsp;0,&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:blue;"&gt;new&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:#2b91af;"&gt;IntPtr&lt;/span&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;(&amp;amp;r),&amp;nbsp;size);&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="BACKGROUND:white;"&gt;&lt;span style="FONT-FAMILY:Consolas;COLOR:black;"&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;COLOR:black;FONT-SIZE:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&lt;/span&gt; 
&lt;p&gt;Don&amp;#39;t forget to compile with /unsafe flag.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=806963" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CloudValue/default.aspx">CloudValue</category></item><item><title>MSDN Israel Event–Introducing Windows Azure</title><link>http://blogs.microsoft.co.il/blogs/alon/archive/2011/01/20/msdn-israel-event-introducing-windows-azure.aspx</link><pubDate>Thu, 20 Jan 2011 21:58:24 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:775613</guid><dc:creator>Alon Fliess</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/rsscomments.aspx?PostID=775613</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/alon/commentapi.aspx?PostID=775613</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/alon/archive/2011/01/20/msdn-israel-event-introducing-windows-azure.aspx#comments</comments><description>&lt;p&gt;&lt;img src="http://hphotos-ash1.fbcdn.net/hs821.ash1/171119_174710509237207_137001249674800_328476_4493790_o.jpg" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://arnon.me/" target="_blank"&gt;Arnon&lt;/a&gt; and I would like to thank all the people that attended today the Introducing &lt;a href="http://www.microsoft.com/windowsazure/windowsazure/" target="_blank"&gt;Windows Azure&lt;/a&gt; lecture. The feedbacks (verbal and written) were great, thank you. As I said in the lecture, one of the best ways to further learning how to develop to Windows Azure is the &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=413e88f8-5966-4a83-b309-53b7b77edf78&amp;amp;displaylang=en" target="_blank"&gt;Windows Azure training kit&lt;/a&gt;. Beside that you can watch and read the materials from the &lt;a href="http://player.microsoftpdc.com/session" target="_blank"&gt;last PDC&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;To those of you that couldn&amp;#39;t come to this event, I will briefly describe what we delivered:&lt;/p&gt;  &lt;p&gt;In the first lecture we introduced the whole &lt;a href="http://en.wikipedia.org/wiki/Cloud_computing"&gt;cloud&lt;/a&gt; concept, we showed the &lt;a href="http://msdn.microsoft.com/en-us/library/dd179367.aspx" target="_blank"&gt;development tools&lt;/a&gt;, and got &lt;a href="http://bit.ly/977D0A" target="_blank"&gt;into the bits and bytes&lt;/a&gt; of the Azure O/S. The second lecture dealt with &lt;a href="http://bit.ly/bfu1iw" target="_blank"&gt;Azure storage&lt;/a&gt;, we explained each storage mechanisms talking about the why, how and when to use each of them. In the 3&lt;sup&gt;rd&lt;/sup&gt; lecture Arnon talked about cloud architecture, and showed the many facilities to build a robust, high available and scalable application. We showed how to use the Service Bus and the Access Control Service (ACS). The last lecture was about the porting process – the best practices you need to know when doing the Windows Azure migration project. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/alon/Azure-Twitter-Architecture_5EE16CC2.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="Azure Twitter Architecture" border="0" alt="Azure Twitter Architecture" src="http://blogs.microsoft.co.il/blogs/alon/Azure-Twitter-Architecture_thumb_65845078.png" width="646" height="482" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;During the day we had several demos, we showed a Twitter management system that collect tweets and response back. We also showed how I can control my electrical system at home using the ability of the service bus to go throw firewalls, routers and NATs. &lt;/p&gt;  &lt;p&gt;I hope that we will have the chance to have another session like the one we delivered today.&lt;/p&gt;  &lt;p&gt;Last but not least, please sign to our &lt;a href="http://cloudvalue.com/" target="_blank"&gt;Cloudoscope™&lt;/a&gt; beta program, it will help us (and you) to do the right thing when driving or shell I say flying your application to the cloud!&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=775613" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Windows+Azure/default.aspx">Windows Azure</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Home+Automation/default.aspx">Home Automation</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/VS+2010/default.aspx">VS 2010</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/CodeValue/default.aspx">CodeValue</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Cloudoscope/default.aspx">Cloudoscope</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/Microsoft+Israel/default.aspx">Microsoft Israel</category><category domain="http://blogs.microsoft.co.il/blogs/alon/archive/tags/MSDN+Event/default.aspx">MSDN Event</category></item></channel></rss>
