<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Janne Mattila's blog</title><subtitle type="html">From programmer to programmer -- Programming just for the fun of it</subtitle><id>http://blogs.msdn.com/jannemattila/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/jannemattila/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-05-29T18:14:50Z</updated><entry><title>Live Mesh + Visual SourceSafe = Code everywhere!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/11/06/live-mesh-visual-sourcesafe-code-everywhere.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/11/06/live-mesh-visual-sourcesafe-code-everywhere.aspx</id><published>2009-11-06T12:32:12Z</published><updated>2009-11-06T12:32:12Z</updated><content type="html">&lt;p&gt;For long time I have wanted have my code _&lt;em&gt;everywhere&lt;/em&gt;_. Just because I have 3 different computers that I use to write my own stuff. Obviously it would be nice to have version control system (such as Team Foundation Server) but for my own use it would be quite heavy solution. And many times when I have had inspiration to start development of my old project I haven’t had network connectivity at that moment &lt;strong&gt;:-(&lt;/strong&gt; So I thought that I try untraditional solution: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use Visual SourceSafe for source control &lt;/li&gt;    &lt;li&gt;Synchronize VSS database across all my computers with &lt;a href="http://www.mesh.com/" target="_blank"&gt;Live Mesh&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Use local VSS database and “get latest” from that in each computer&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I know that this sounds &lt;strong&gt;*weird*&lt;/strong&gt; but it turns out to be good and working solution! Now I can take my source from local VSS database whenever I need and it’s always up to date (since Live Mesh is constantly running on the background and it does all the synchronization stuff). &lt;/p&gt;  &lt;p&gt;Future will show if I manage to destroy my VSS database using this this approach &lt;strong&gt;:-)&lt;/strong&gt;     &lt;br /&gt;    &lt;br /&gt;Anyways... Happy hacking!     &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9918543" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /></entry><entry><title>My Chess (another chess application)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/10/22/my-chess-another-chess-application.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/10/22/my-chess-another-chess-application.aspx</id><published>2009-10-22T14:43:04Z</published><updated>2009-10-22T14:43:04Z</updated><content type="html">&lt;p&gt;I came up with the idea of &lt;em&gt;My Chess&lt;/em&gt; when I wanted to play games with my friends and I noticed that I don’t have time to do that &lt;strong&gt;:-)&lt;/strong&gt; So I decided to write an application that allows me to play chess with my friends just by using small amount of time every now and then (approach is pretty different compared to the “&lt;em&gt;normal&lt;/em&gt;” chess). Small amount of time means something like 10 seconds per move so and not more... Of course if you WANT to use more time you’re allowed to do that.&lt;/p&gt;  &lt;p&gt;Here is list of other &lt;em&gt;features&lt;/em&gt; that I wanted from &lt;em&gt;My Chess&lt;/em&gt;:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Possibility to play offline. In another words I don’t want to think about the transport at all. I would just like to pass the transport related stuff to someone else. &lt;/li&gt;    &lt;li&gt;Mobile version of the application (HTC Touch Pro since I have one) &lt;/li&gt;    &lt;li&gt;“Social chess”: I wanted to have possibility to add comment when making move. Just because I want to tell to my opponents how good move I have made and remind them about their bad ones &lt;strong&gt;:-)&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Game should be fast and easy. You should be able to make your move with just few clicks. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I decided to go with C++ since I didn’t want to take start up delay of .NET application on my mobile device. This one was easy decision :-)&lt;/p&gt;  &lt;p&gt;Then I thought that I could use email as my transport because it automatically solves issues with the connectivity. On desktop I could rely on Outlook and mobile device I could rely on Pocket Outlook. More about technical details later in this post. &lt;/p&gt;  &lt;p&gt;But then I was forced to think proper way to solve how to transmit the game state. I mean that how could I pass the current state of the game to my opponent so that it would be easy for him/her to continue from that state.&amp;#160; Use of attachment at the email was one option. But the story for the end user on mobile device with attachments isn’t that good so I didn’t use effort on this option. I took another approach which was to define URL format that I could use to serialize the game state. Here is one example game state:    &lt;br /&gt;&lt;em&gt;my://chess/MczrFh7z?w=player1@contoso.com%26b=player2@contoso.com&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Game state uses &lt;em&gt;my&lt;/em&gt; protocol which I have mapped to application (&lt;a href="http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx" target="_blank"&gt;Registering an Application to a URL Protocol&lt;/a&gt; on MSDN). Of course &lt;em&gt;My Chess&lt;/em&gt; is configured according to the article so that it will called when &lt;em&gt;my &lt;/em&gt;protocol is launched. Here is example &lt;em&gt;.reg&lt;/em&gt; how custom application can be mapped to protocol:&lt;/p&gt;  &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\my]
@=&amp;quot;URL:My Chess Protocol&amp;quot;
&amp;quot;URL Protocol&amp;quot;=&amp;quot;&amp;quot;

[HKEY_CLASSES_ROOT\my\shell]

[HKEY_CLASSES_ROOT\my\shell\open]

[HKEY_CLASSES_ROOT\my\shell\open\command]
@=&amp;quot;\&amp;quot;C:\\path\\My Chess (x64).exe\&amp;quot; %1&amp;quot;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;So it really is that simple. Just define own key under HKEY_CLASSES_ROOT and set path to your application and it will be called automatically by the OS.&lt;/p&gt;

&lt;p&gt;If you look the same with &lt;em&gt;regedit&lt;/em&gt; it looks like this: &lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Registry" border="0" alt="Registry" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Registry_6.png" width="806" height="381" /&gt;&lt;/p&gt;

&lt;p&gt;If you now open up links starting with &lt;em&gt;my&lt;/em&gt; protocol they will eventually take you to the configured application. But you probably see this kind of security dialogs before your own application starts (at least for the first time): 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="IE Confirmation dialog" border="0" alt="IE Confirmation dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/IE%20Confirmation_1.png" width="599" height="377" /&gt;&amp;#160; &lt;br /&gt;Just uncheck “&lt;em&gt;Always ask before opening this type of address&lt;/em&gt;” and press &lt;em&gt;Allow&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="My Chess Security Warning" border="0" alt="My Chess Security Warning" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/image_15.png" width="486" height="302" /&gt;&lt;/p&gt;

&lt;p&gt;Same goes with this dialog. Just check “&lt;em&gt;Do not show me the warning for this program again”&lt;/em&gt; and press &lt;em&gt;Allow&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;em&gt;&lt;strong&gt; &lt;/strong&gt;Make sure you understand the consequences of allowing protocol to map to application. If you’re application doesn’t validate data correctly it may lead to security issues when someone passes malicious data to your application. Remember you have been warned!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After that you should finally be at your application and you can use the information passed on the command line to execute the required actions.&lt;/p&gt;

&lt;p&gt;So basically now I have tools to build the application... But I haven’t yet solved the “&lt;em&gt;creating the email message&lt;/em&gt;” part of this solution. Remember I have both desktop application and mobile application to built.&lt;/p&gt;

&lt;p&gt;On desktop I’m using Outlook as my mail transport and it has pretty good instructions in here: 
  &lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/259298" target="_blank"&gt;How to use an Outlook Object Model from Visual C++ by using a #import statement&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/199870" target="_blank"&gt;How To Send a Message by Outlook Object Model with VC++&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using Outlook on desktop with C++ is almost as easy as using it from .NET. It’s straight forward thing. So far so good right!&lt;/p&gt;

&lt;p&gt;On mobile device things aren’t quite that easy since you need to use MAPI for sending the mail message. Here are few examples for that: 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/windowsmobile/archive/2007/03/21/getting-started-with-mapi.aspx" target="_blank"&gt;Getting Started with MAPI&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/windowsmobile/archive/2007/04/23/practical-use-of-mapi.aspx" target="_blank"&gt;Practical Use of MAPI&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/raffael/archive/2008/09/08/mapi-on-windows-mobile-6-programmatically-retrieve-mail-body-sample-code.aspx" target="_blank"&gt;MAPI on Windows Mobile 6: Programmatically retrieve mail BODY (sample code)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But as always things aren’t as easy as they first seem to be. Since even if I did register &lt;em&gt;my&lt;/em&gt; protocol at the mobile device it didn’t work as I expected. The problem was that Pocket Outlook always launched the URL to the default browser even if I had registration done to my own protocol. After some digging I found out that there are many security features that prevent that from happening. So in order to do it the &lt;em&gt;right way&lt;/em&gt; I should have to edit/configure some files to allow protocol to be launched correctly. But since this is more &lt;em&gt;concept&lt;/em&gt; than &lt;em&gt;production kind-of-application&lt;/em&gt; I took another route... I chose to &lt;strong&gt;*hijack*&lt;/strong&gt; MMS protocol for my custom application :-) I did that because it’s one of those protocols that are configured properly to the system. It normally launches Windows Media Player but I changed that to launch &lt;em&gt;My Chess&lt;/em&gt; instead. This is the reason why you see two links at the emails underneath. The URL structure is exactly the same... Only the protocol part is either &lt;em&gt;my&lt;/em&gt; or &lt;em&gt;mms&lt;/em&gt; depending on the link. I admit that this one was dirty hack...&lt;/p&gt;

&lt;p&gt;Now we have solved pretty much everything. But what about graphics then? Well I used images from Wikipedia at the &lt;a href="http://en.wikipedia.org/wiki/Chess_piece" target="_blank"&gt;Chess piece&lt;/a&gt; article (example &lt;a href="http://en.wikipedia.org/wiki/File:Chess_kdt45.svg" target="_blank"&gt;King&lt;/a&gt; where you can see the licenses as well). Graphics is another interesting difference between desktop application and mobile application since GDI+ headers and libraries aren’t available for the mobile environment :-( But I wanted to use GDI+ on my desktop application even if I was forced to use GDI at the mobile application. Yeah I know... someone else would have built them using the same codebase but not me.&lt;/p&gt;

&lt;p&gt;I used following functionalities from GDI+: Bitmap, Graphics (DrawImage, DrawCachedBitmap, DrawRectangle, FillRectangle), Graphics::FromImage, FontFamily, Font, SolidBrush, Pen, CachedBitmap etc.&lt;/p&gt;

&lt;p&gt;I used following functionalities from GDI: DeleteDC, DeleteObject, CreateCompatibleDC, CreateCompatibleBitmap, SelectObject, Rectangle, TransparentBlt, BitBlt etc.&lt;/p&gt;

&lt;p&gt;Are you already eager to see the final outcome? Well here it goes:&lt;/p&gt;

&lt;p&gt;Desktop version:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="My Chess" border="0" alt="My Chess" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/My%20Chess_2.png" width="609" height="610" /&gt; &lt;/p&gt;

&lt;p&gt;Mobile version (screenshot from emulator. It looks better on real device):&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="My Chess (Mobile)" border="0" alt="My Chess (Mobile)" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/My%20Chess%20Mobile_3.png" width="373" height="570" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So how does it work in real life? Here is small example:&lt;/p&gt;

&lt;p&gt;First if start &lt;em&gt;My Chess&lt;/em&gt; without parameters so it creates automatically new game (in this example I play against myself): 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="My Chess new game dialog" border="0" alt="My Chess new game dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email0_1.png" width="502" height="204" /&gt;&lt;/p&gt;

&lt;p&gt;In order to update the registry correctly for the protocol &lt;em&gt;My Chess&lt;/em&gt; needs to be run for the first time in the “&lt;em&gt;Run as administrator”&lt;/em&gt; –mode:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Run as administrator in order to register the protocol" border="0" alt="Run as administrator in order to register the protocol" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/image_6.png" width="365" height="79" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So now you have new game and you can use mouse to make the move (see simple coloring to indicate the move): 
  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Coloring of the move" border="0" alt="Coloring of the move" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/image_9.png" width="145" height="318" /&gt; &lt;/p&gt;

&lt;p&gt;When you have done that you can press &lt;em&gt;Send&lt;/em&gt; menu which then creates email message for you where you can add your own comment to your move (everything else is generated.. you just need to add last line): 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="My Chess created email message to Outlook" border="0" alt="My Chess created email message to Outlook" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email_1.png" width="448" height="398" /&gt; 

  &lt;br /&gt;Now the game state is passed to the opponent as just normal email. When opponent receives it and presses the link following security prompt is displayed (Note: on mobile device application is launched directly without any dialogs): 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Outlook Security Notice on my protocol link" border="0" alt="Outlook Security Notice on my protocol link" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email2_1.png" width="570" height="499" /&gt; 

  &lt;br /&gt;After that &lt;em&gt;My Chess&lt;/em&gt; is opened and it’s opens the current game state directly: 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Email3" border="0" alt="Email3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyChess_87EA/Email3_1.png" width="630" height="628" /&gt;&amp;#160;&amp;#160; &lt;br /&gt;And now you’re ready to make your move and then send it to the opponent with some nasty comment of course. &lt;/p&gt;

&lt;p&gt;Current status of the &lt;em&gt;My Chess&lt;/em&gt; is pretty much &lt;em&gt;experimental&lt;/em&gt; / &lt;em&gt;concept state&lt;/em&gt; since I haven’t yet implemented all the necessary functions to make it &lt;em&gt;_real_&lt;/em&gt; chess application:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Move validation is currently missing and all special moves haven’t been implemented (promotion is only special move that has been implemented) &lt;/li&gt;

  &lt;li&gt;Currently there isn’t way to see previous move or move history (it’s stored behind the covers but it’s not visible). I’m going to implement animations so that when user opens &lt;em&gt;My Chess&lt;/em&gt; something like last 3 moves of the game would be animated. And user could browse the move history (with animations of course!) to see what has happened previously on the game. &lt;/li&gt;

  &lt;li&gt;I &lt;em&gt;could&lt;/em&gt; CC the email message to email box that could be read by machine. It then could insert the game state to database, create some statistics about the games, history of games etc. This brings more possibilities to extend the game in the future. But I probably leave this to someone else...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the way... you might have noticed that I used &lt;em&gt;chess&lt;/em&gt; as in my URL to define which game should be launched from the &lt;em&gt;my&lt;/em&gt; protocol. This indicates that something else might come in the future. That remains to be seen! &lt;/p&gt;

&lt;p&gt;How could you use information provided in this blog entry for your own needs? Well here’s one: I have many times heard that customers need to “Send shortcuts” from their existing applications to each other. This could be way to do that. Just add functionality to “copy shortcut” from applications current state and then allow user to send it. Then at the receiving end you could create “proxy application” that interprets received information and opens the application into same state that the other user had. It could be pretty good improvement in many cases. 
  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking! 

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9911395" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="Fun" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx" /><category term="C/C++" scheme="http://blogs.msdn.com/jannemattila/archive/tags/C_2F00_C_2B002B00_/default.aspx" /><category term="Mobile" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Mobile/default.aspx" /></entry><entry><title>My Notes (a small application between notepad and OneNote)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/04/30/my-notes-a-small-application-between-notepad-and-onenote.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/04/30/my-notes-a-small-application-between-notepad-and-onenote.aspx</id><published>2009-04-30T10:20:59Z</published><updated>2009-04-30T10:20:59Z</updated><content type="html">&lt;p&gt;I have been using Windows 7 and&amp;#160; Windows Server 2008 R2 since the first beta. And I mean on my “&lt;em&gt;production&lt;/em&gt;” laptops. And I have to say that I haven’t had any major issues with them. In fact I’ve used to them so much that I don’t want to use older versions anymore &lt;strong&gt;:-) &lt;/strong&gt;And there are few improvements in them that I specially enjoy. Of course the biggest one is the new taskbar... But surprisingly I have also found new application that I have “always needed”: &lt;strong&gt;Sticky Notes&lt;/strong&gt;!&lt;/p&gt;  &lt;p&gt;Sticky Notes is small application where you can write small notes to yourself. I call it “&lt;em&gt;something between notepad and OneNote&lt;/em&gt;”. Reason for that is the fact that notepad is lightweight but it doesn’t contain &lt;u&gt;any&lt;/u&gt; features. OneNote is full-blown application with &lt;u&gt;tons&lt;/u&gt; of features. Sticky Notes lives between those too... It contains just &lt;u&gt;enough&lt;/u&gt; features that make it useful and it also looks nice! The only issue I’m having with the Sticky Notes is the fact that it comes with Windows 7 only &lt;strong&gt;:-(&lt;/strong&gt; So in my main “&lt;em&gt;production&lt;/em&gt;” laptop (which is R2) I don’t have sticky notes.&lt;/p&gt;  &lt;p&gt;For me it was a bit disappointing but I still understood the logic for that. Of course Sticky Notes isn’t “something that you would expect on the server” but since I really need this kind of application... I was forced to create one &lt;strong&gt;:-) &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Normally when I create application I’ll just create new .NET project and start writing the application. But now I don’t want to suffer this penalty (screenshot taken from “&lt;em&gt;File –&amp;gt; New Project: Windows Forms Application –&amp;gt; Run&lt;/em&gt;”):&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title=".NET Windows Forms application" border="0" alt=".NET Windows Forms application" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_12.png" width="463" height="218" /&gt;&amp;#160; &lt;br /&gt;Downside of .NET applications is the memory usage. Normally I don’t care about it but since now I’m going to create application that will be “always on” I just have to care about it. I don’t want to waste too much memory (I only have 8 GB of it :-). Therefore I decided to go with the native way (Win32, C/C++ or whatever you like to call it). It gives me possibility to be in control of all the used resources.&lt;/p&gt;  &lt;p&gt;And here is the result “&lt;em&gt;My Notes&lt;/em&gt;” application:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="My Notes - Example" border="0" alt="My Notes - Example" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_3.png" width="546" height="272" /&gt; &lt;/p&gt;  &lt;p&gt;I’ve hidden the menus and tried to make the borders as small as possible. I don’t want to waste space as much the normal Windows application does:    &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Standard windows application" border="0" alt="Standard windows application" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_9.png" width="380" height="233" /&gt;&amp;#160; &lt;br /&gt;“Standard” windows application doesn’t look that good either. So therefore I wanted to give it a bit more “fresh and appealing looks”. I used GDI+ and &lt;em&gt;LinearGradientBrush&lt;/em&gt; to make it fancier. In case your wondering how to add GDI+ to your native application then it’s just this simple:&lt;/p&gt;  &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;

GdiplusStartup(&amp;amp;gdiplusToken, &amp;amp;gdiplusStartupInput, NULL);
&lt;font color="#008000"&gt;// ...
&lt;/font&gt;GdiplusShutdown(gdiplusToken);&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;See more about GDI+ on MSDN if your &lt;a href="http://msdn.microsoft.com/en-us/library/ms534077(VS.85).aspx" target="_blank"&gt;interested&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Even if I wanted the application to small borders I didn’t want to completely remove the menus. I used same thing as in IE for example... pressing &lt;em&gt;Alt&lt;/em&gt; brings in the menu:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="My Notes - Menu visible" border="0" alt="My Notes - Menu visible" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_6.png" width="217" height="70" /&gt; &lt;/p&gt;

&lt;p&gt;I also wanted to give myself possibility to extend the application little bit more and I also added context menu to the edit surface. I don’t know yet what to put there but it’s nice to have if I need it someday &lt;strong&gt;:-)
    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="My Notes - Content menu" border="0" alt="My Notes - Content menu" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_27.png" width="322" height="122" /&gt; &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I had to add “graphical menu” for basic operations like New and Close (just for fun):&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="My Notes - Graphical menu" border="0" alt="My Notes - Graphical menu" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_15.png" width="545" height="40" /&gt; &lt;/p&gt;

&lt;p&gt;Graphical menu is only visible if mouse is on top of the so called caption bar (as in screenshot).&lt;/p&gt;

&lt;p&gt;And of course this should be in x64 since I’m running my R2 on x64:
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VS Configuration Manager dialog" border="0" alt="VS Configuration Manager dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_18.png" width="717" height="451" /&gt; &lt;/p&gt;

&lt;p&gt;If your wondering why you don’t have the option to use &lt;em&gt;x64&lt;/em&gt; then you haven’t most likely checked the option in the Visual Studio setup. Just go to &lt;em&gt;Control Panel&lt;/em&gt; and locate VS and select option to change the setup:

  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Control panel - Visual Studio" border="0" alt="Control panel - Visual Studio" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_21.png" width="427" height="53" /&gt;&amp;#160; &lt;br /&gt;Then just check the &lt;em&gt;x64&lt;/em&gt; if that’s what you want:

  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VS setup" border="0" alt="VS setup" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/MyNotes_1444F/image_24.png" width="332" height="320" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And last but not least... I’ve put my &lt;em&gt;My Notes&lt;/em&gt; to the &lt;a href="https://www.mesh.com/welcome/default.aspx" target="_blank"&gt;Live Mesh&lt;/a&gt; folder and synchronized my content to other devices. It’s simple and since I’m saving my note content to Rich Text Format (RTF) I can open up my notes even in my Windows Mobile. So now I have pretty good solution for my notes.

  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking!

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9578916" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="Fun" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx" /><category term="C/C++" scheme="http://blogs.msdn.com/jannemattila/archive/tags/C_2F00_C_2B002B00_/default.aspx" /></entry><entry><title>Story of wrong content type and InfoPath publishing location</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/04/29/story-of-wrong-content-type-and-infopath-publishing-location.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/04/29/story-of-wrong-content-type-and-infopath-publishing-location.aspx</id><published>2009-04-29T13:54:35Z</published><updated>2009-04-29T13:54:35Z</updated><content type="html">&lt;p&gt;I found myself troubleshooting on issue that I thought shouldn’t be issue anymore. I have created InfoPath form and published it to the SharePoint. However when I created new form using that template it ended up using wrong content type at my library. And this happens even with the SP2 installed (both at the client and at the server) so I had to dig a little deeper.&lt;/p&gt;  &lt;p&gt;Here are the phases that I took:&lt;/p&gt;  &lt;p&gt;1. Created new InfoPath “Example form”.   &lt;br /&gt;2. Published it to the server called “&lt;em&gt;myserver&lt;/em&gt;” as an site content type.    &lt;br /&gt;3. Added new content type to “&lt;em&gt;mylist&lt;/em&gt;”.    &lt;br /&gt;4. Clicked “New example form” on the library and filled the form and saved it to the library.    &lt;br /&gt;5. Noticed that form is not the content type that I was expecting. It was default content type at the list... (which was Office document in my case since I had multiple content types at my list)&lt;/p&gt;  &lt;p&gt;Did some testing and noticed that it actually works fine &lt;strong&gt;IF&lt;/strong&gt; I use the “&lt;em&gt;myserver&lt;/em&gt;” in the address bar of IE and not the fully qualified domain name “&lt;em&gt;myserver.example.loc&lt;/em&gt;”. And now you’re thinking that I’ve just missed the Alternate Access Mappings (AAM) settings but &lt;strong&gt;&lt;u&gt;no&lt;/u&gt;&lt;/strong&gt;... I have those set for both addresses so that wasn’t the case.&lt;/p&gt;  &lt;p&gt;Next I tried to fiddle around with InfoPath and tried different publishing addresses at the “&lt;em&gt;Enter the location of your SharePoint or InfoPath Forms Services site:”&lt;/em&gt; –publishing wizard dialog:    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="InfoPath publishing wizard dialog" border="0" alt="InfoPath publishing wizard dialog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Storyofwrongcontenttypeandpublishingloca_A6CD/image_3.png" width="584" height="441" /&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;And this is the place when it got interesting... Since I noticed that if I use “&lt;em&gt;myserver&lt;/em&gt;” address at the publishing wizard dialog then content type goes wrong when using SharePoint through “&lt;em&gt;myserver.example.loc&lt;/em&gt;” address. And also if I use the longer address at the publish wizard it doesn’t work at the SharePoint using the short address form.&lt;/p&gt;  &lt;p&gt;So next I thought that &lt;em&gt;Security Level&lt;/em&gt; could be the problem (which was set to &lt;em&gt;Domain&lt;/em&gt;):    &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="InfoPath publishing wizard dialog - Security level: Domain" border="0" alt="InfoPath publishing wizard dialog - Security level: Domain" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/Storyofwrongcontenttypeandpublishingloca_A6CD/image_6.png" width="586" height="441" /&gt; &lt;/p&gt;  &lt;p&gt;...but if that would be the case then I couldn’t even use the form. Now the form works normally expect it will store the saved item into wrong content type. &lt;/p&gt;  &lt;p&gt;For me the case was closed. I just published the form in “long address format” and I was happy &lt;strong&gt;:-)&lt;/strong&gt; But I still wonder what went wrong in the background...    &lt;br /&gt;    &lt;br /&gt;Anyways... Happy hacking!    &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9575497" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Microsoft Office SharePoint Server 2007" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx" /><category term="InfoPath" scheme="http://blogs.msdn.com/jannemattila/archive/tags/InfoPath/default.aspx" /></entry><entry><title>Treasure hunting with Microsoft Tag</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/03/31/treasure-hunting-with-microsoft-tag.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/03/31/treasure-hunting-with-microsoft-tag.aspx</id><published>2009-03-31T22:58:49Z</published><updated>2009-03-31T22:58:49Z</updated><content type="html">&lt;p&gt;Many people know &lt;a href="http://en.wikipedia.org/wiki/Geocaching" target="_blank"&gt;geocaching (Wikipedia)&lt;/a&gt; and think of it as one of the modern treasure hunting games. Few days ago I found myself playing around with &lt;a href="http://tag.microsoft.com/" target="_blank"&gt;Microsoft Tag&lt;/a&gt; and I thought that this could be another treasure hunting game! Therefore I thought that I’ll do a different post this time.&lt;/p&gt;  &lt;p&gt;First I’ll show how you can try out Microsoft Tag. First go to this page: &lt;a href="http://tag.microsoft.com/" target="_blank"&gt;http://tag.microsoft.com/&lt;/a&gt;. Click on the “Sign Up” –button (or “Sign In” if you have already done so). After sign in you have possibility to create categories, create tags and view reports about your tag usage. &lt;/p&gt;  &lt;p&gt;As an example I’ll create a new tag category:    &lt;br /&gt;&lt;a href="http://tag.microsoft.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create tag category" border="0" alt="Create tag category" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_3.png" width="402" height="329" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And I’ll use “&lt;em&gt;Example tags”&lt;/em&gt; for the name:     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Example tags category" border="0" alt="Example tags category" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_6.png" width="578" height="381" /&gt;&amp;#160; &lt;br /&gt;Then I’m going to create example tag that points to my blog:     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Example link to my blog" border="0" alt="Example link to my blog" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_9.png" width="607" height="746" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;After save has done it’s magic I can go and render my new fancy tag:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_11.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Launch tag rendering" border="0" alt="Launch tag rendering" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_thumb_3.png" width="644" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then it asks me that what kind of rendering do I want:    &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Tag rendering options" border="0" alt="Tag rendering options" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_17.png" width="381" height="566" /&gt;&amp;#160;&amp;#160; &lt;br /&gt;I selected &lt;em&gt;Render Type&lt;/em&gt; as PDF and &lt;em&gt;Plain&lt;/em&gt; as the output format. Of course that result can be then printed out since it’s just image on the PDF. Here is the result:     &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Rendered tag" border="0" alt="Rendered tag" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_20.png" width="501" height="506" /&gt; &lt;/p&gt;  &lt;p&gt;Now you can go to &lt;a href="http://tags.microsoft.com"&gt;http://tags.microsoft.com&lt;/a&gt; with your mobile phone and download Microsoft Tag Reader for your phone. If you go there directly with your brower you can see list of supported platforms:     &lt;br /&gt;&lt;a href="http://tags.microsoft.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Supported phones" border="0" alt="Supported phones" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_23.png" width="298" height="550" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you now start Tag Reader in your phone it will automatically start you phones camera and starts displaying picture from the camera. If you now point it to tag (like the one in this post :-) it recognizes the image and launches the action that I have configured. And since I configured tag to go to this blog you probably ended up to my blog with your mobile browser &lt;strong&gt;:-)&lt;/strong&gt; And that’s cool right!&lt;/p&gt;  &lt;p&gt;And finally we have the tools to build our own treasure hunt game! So now you need to do some planning and then you just create tags to support you treasure hunt game. But I’ll leave you the planning part...&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;NOTE:&lt;/u&gt; &lt;/strong&gt;By the time of writing Microsoft Tag is in Beta phase which means creating of tags is free:     &lt;br /&gt;&lt;a href="http://tags.microsoft.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Beta statement" border="0" alt="Beta statement" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/TreasurehuntingwithMicrosoftTag_126E4/image_26.png" width="463" height="104" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So now it’s your time to go and create few tags!    &lt;br /&gt;    &lt;br /&gt;Anyways... Happy hacking!     &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9523795" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Fun" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx" /></entry><entry><title>Visual Studio 2008: Track Active Item in Solution Explorer</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/02/21/visual-studio-2008-track-active-item-in-solution-explorer.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/02/21/visual-studio-2008-track-active-item-in-solution-explorer.aspx</id><published>2009-02-21T21:58:49Z</published><updated>2009-02-21T21:58:49Z</updated><content type="html">&lt;p&gt;If you’re working on solution that has many projects and many project items and &lt;u&gt;you tend to get lost between your files&lt;/u&gt;... You might want to go to &lt;em&gt;Tools –&amp;gt; Options –&amp;gt; Projects and Solutions&lt;/em&gt; and set &lt;em&gt;Track Active Item in Solution Explorer&lt;/em&gt; on. For me it was a big relief that I found it. I’m working on project that has quite many projects under the solution and I have found myself constantly “searching” for files that are at the same location as the currently open file. And this is the painkiller for that pain:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio 2008 - Track Active Item in Solution Explorer" border="0" alt="Visual Studio 2008 - Track Active Item in Solution Explorer" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/VisualStudio2008TrackActiveIteminSolutio_123FB/image_6.png" width="510" height="251" /&gt;     &lt;br /&gt;    &lt;br /&gt;I’m not sure but if I have to guess... this was on by default on previous version of VS but not anymore on 2008. Because I know that I have enjoyed this feature in the past &lt;strong&gt;:-)&lt;/strong&gt; But I might be wrong and I have manually set that on in the past too.     &lt;br /&gt;    &lt;br /&gt;Anyways... Happy hacking!     &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9437915" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="Visual Studio" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Visual+Studio/default.aspx" /></entry><entry><title>Creating Excel Game (or something similar for fun)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2009/01/29/creating-excel-game-or-something-similar-for-fun.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2009/01/29/creating-excel-game-or-something-similar-for-fun.aspx</id><published>2009-01-29T22:47:33Z</published><updated>2009-01-29T22:47:33Z</updated><content type="html">&lt;p&gt;Awhile back I saw really interesting article: &lt;a href=" http://www.gamasutra.com/view/feature/3563/microsoft_excel_revolutionary_3d_.php" target="_blank"&gt;Microsoft Excel: Revolutionary 3D Game Engine?&lt;/a&gt;     &lt;br /&gt;After that I was forced to do small test on that and that of course resulted to this post &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I just grabbed the idea and made small “car game” (but in reality it just vaguely reminds of car game) on top of Excel. And here is the result: &lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_11.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Car Game example" border="0" alt="Car Game example" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_thumb_3.png" width="639" height="480" /&gt;&lt;/a&gt;     &lt;br /&gt;My car (or just blue box if you wish) can be controlled with mouse. If you press left mouse button it increases the speed of the car (a.k.a. gas pedal). I was too lazy to “invent” brake so car just slowly slows down if user isn’t pressing the left mouse button. User can control the “car” by moving mouse from left to right. Right mouse button quits the game.&lt;/p&gt;  &lt;h4&gt;Click here for the &lt;a href="http://cid-64286c13c6bd5d77.skydrive.live.com/self.aspx/Julkinen/Blog%20files/ExcelCarGame.wmv" target="_blank"&gt;video&lt;/a&gt;.&lt;/h4&gt; Since I just wanted to test basic input and drawing mechanisms I didn’t even bother to think of creating any physics. I’ll leave that to you! But here’s the source code for my example:   &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;&lt;font color="#008000"&gt;' WinAPI stuff:
&lt;/font&gt;&lt;font color="#0000ff"&gt;Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub&lt;/font&gt; Sleep &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;kernel32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByVal&lt;/font&gt; dwMilliseconds &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long&lt;/font&gt;)
&lt;font color="#0000ff"&gt;Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Function&lt;/font&gt; GetAsyncKeyState &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;user32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByVal&lt;/font&gt; vKey &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long&lt;/font&gt;) &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Integer
Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub&lt;/font&gt; GetCursorPos &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;user32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByRef&lt;/font&gt; lpoint &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI)
&lt;font color="#0000ff"&gt;Declare&lt;/font&gt; &lt;font color="#0000ff"&gt;Function&lt;/font&gt; ShowCursor &lt;font color="#0000ff"&gt;Lib&lt;/font&gt; &lt;font color="#a31515"&gt;&amp;quot;user32&amp;quot;&lt;/font&gt; (&lt;font color="#0000ff"&gt;ByVal&lt;/font&gt; bShow &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long&lt;/font&gt;) &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long

Type&lt;/font&gt; POINTAPI
  x &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long
&lt;/font&gt;  y &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Long
End&lt;/font&gt; &lt;font color="#0000ff"&gt;Type&lt;/font&gt; 

&lt;font color="#0000ff"&gt;Sub&lt;/font&gt; GameLoop()

  &lt;font color="#008000"&gt;' Input related variables:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; mouseLocation &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI
  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; mouseLocationPrevious &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI

  &lt;font color="#008000"&gt;' Get &amp;amp; Set original mouse position:
&lt;/font&gt;  GetCursorPos mouseLocation
  mouseLocationPrevious = mouseLocation

  &lt;font color="#008000"&gt;' Initialize the system:
&lt;/font&gt;  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Xdiff&amp;quot;&lt;/font&gt;).Value = 0
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Ydiff&amp;quot;&lt;/font&gt;).Value = 0
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value = 90
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = 0
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value = 250
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value = 250

  &lt;font color="#008000"&gt;' Hide mouse cursor:
&lt;/font&gt;  ShowCursor 0

  &lt;font color="#008000"&gt;' We're going to loop until mouse click:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;While&lt;/font&gt; GetAsyncKeyState(vbKeyRButton) = 0

    &lt;font color="#008000"&gt;' Magic:
&lt;/font&gt;    Sheets(&lt;font color="#a31515"&gt;&amp;quot;GameBoard&amp;quot;&lt;/font&gt;).Range(&lt;font color="#a31515"&gt;&amp;quot;Z_SortArea&amp;quot;&lt;/font&gt;).Sort _
      Sheets(&lt;font color="#a31515"&gt;&amp;quot;GameBoard&amp;quot;&lt;/font&gt;).Range(&lt;font color="#a31515"&gt;&amp;quot;NormalZ&amp;quot;&lt;/font&gt;), xlAscending

    GetCursorPos mouseLocation
    DrawCar &lt;font color="#a31515"&gt;&amp;quot;car1&amp;quot;&lt;/font&gt;, mouseLocation, mouseLocationPrevious

    ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value = _
      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value - ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SpeedY&amp;quot;&lt;/font&gt;).Value
    ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value = _
      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value - ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SpeedX&amp;quot;&lt;/font&gt;).Value
    mouseLocationPrevious = mouseLocation

    &lt;font color="#008000"&gt;' Let’s take a nap:
&lt;/font&gt;    Sleep(10)

    &lt;font color="#0000ff"&gt;If&lt;/font&gt; GetAsyncKeyState(vbKeyLButton) &amp;lt;&amp;gt; 0 &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;      &lt;font color="#008000"&gt;' User is pressing the gas pedal =&amp;gt; More speed:
&lt;/font&gt;      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = _
        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value + ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Accelerate&amp;quot;&lt;/font&gt;).Value
      &lt;font color="#0000ff"&gt;If&lt;/font&gt; ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value &amp;gt; ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;MaxPedal&amp;quot;&lt;/font&gt;).Value &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;MaxPedal&amp;quot;&lt;/font&gt;).Value
      &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;    &lt;font color="#0000ff"&gt;Else
&lt;/font&gt;      &lt;font color="#008000"&gt;' User isn't pressing the gas pedal =&amp;gt; Take of some speed (if moving):
&lt;/font&gt;      ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = _
        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value - ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Brake&amp;quot;&lt;/font&gt;).Value
      &lt;font color="#0000ff"&gt;If&lt;/font&gt; ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value &amp;lt; 0 &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;        ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Pedal&amp;quot;&lt;/font&gt;).Value = 0
      &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;    &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;  &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;While

&lt;/font&gt;  &lt;font color="#008000"&gt;' Bring back the mouse cursor:
&lt;/font&gt;  ShowCursor 1
&lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub

Sub&lt;/font&gt; DrawCar(carID &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;String&lt;/font&gt;, _
  mouseLocation &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI, _
  mouseLocationPrevious &lt;font color="#0000ff"&gt;As&lt;/font&gt; POINTAPI)

  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; diffX &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; diffY &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; Points(1 &lt;font color="#0000ff"&gt;To&lt;/font&gt; 5, 1 &lt;font color="#0000ff"&gt;To&lt;/font&gt; 2) &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Single

&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carX &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carY &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carWidth &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; carHeight &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Double

&lt;/font&gt;  carX = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarX&amp;quot;&lt;/font&gt;).Value
  carY = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarY&amp;quot;&lt;/font&gt;).Value
  carHeight = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarSize1&amp;quot;&lt;/font&gt;).Value
  carWidth = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;CarSize2&amp;quot;&lt;/font&gt;).Value

  &lt;font color="#008000"&gt;' Get input and store current values to sheet:
&lt;/font&gt;  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Xdiff&amp;quot;&lt;/font&gt;).Value = mouseLocationPrevious.x - mouseLocation.x
  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Ydiff&amp;quot;&lt;/font&gt;).Value = mouseLocationPrevious.y - mouseLocation.y

  ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value = _
    ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value + ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;Xdiff2&amp;quot;&lt;/font&gt;).Value

  Points(1, 1) = carX - carWidth
  Points(1, 2) = carY + carHeight
  Points(2, 1) = carX + carWidth
  Points(2, 2) = carY + carHeight
  Points(3, 1) = carX + carWidth
  Points(3, 2) = carY - carHeight
  Points(4, 1) = carX - carWidth
  Points(4, 2) = carY - carHeight
  Points(5, 1) = Points(1, 1)
  Points(5, 2) = Points(1, 2)

  &lt;font color="#008000"&gt;' Draw this car:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;On&lt;/font&gt; &lt;font color="#0000ff"&gt;Error&lt;/font&gt; &lt;font color="#0000ff"&gt;Resume&lt;/font&gt; &lt;font color="#0000ff"&gt;Next
&lt;/font&gt;  ActiveSheet.Shapes(carID).Delete
  Err.Clear &lt;font color="#008000"&gt;' Deleting Shape that doesn't exist =&amp;gt; Error
&lt;/font&gt;  ActiveSheet.Shapes.AddPolyline(Points).Name = carID
  ActiveSheet.Shapes(carID).Rotation = ActiveSheet.Range(&lt;font color="#a31515"&gt;&amp;quot;SteeringWheel&amp;quot;&lt;/font&gt;).Value
&lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;I did my tests on Excel 2007 and I used &lt;em&gt;.xlsm&lt;/em&gt; format (Macro enabled). You can grab my file from &lt;a href="http://cid-64286c13c6bd5d77.skydrive.live.com/self.aspx/Julkinen/Blog%20files/Car%20Game.xlsm" target="_blank"&gt;here&lt;/a&gt;. 

  &lt;br /&gt;

  &lt;br /&gt;So if you want to open that example it gives you this security warning: 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Security warning" border="0" alt="Security warning" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_6.png" width="390" height="80" /&gt; 

  &lt;br /&gt;

  &lt;br /&gt;You need to click &lt;em&gt;Options...&lt;/em&gt; button just below ribbon. And then check &lt;em&gt;Enable this content&lt;/em&gt; and click &lt;em&gt;OK&lt;/em&gt;: 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Security Alert - Macro" border="0" alt="Security Alert - Macro" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_5.png" width="485" height="429" /&gt; 

  &lt;br /&gt;

  &lt;br /&gt;And if you want to run the game you can just press &lt;em&gt;Alt-F8&lt;/em&gt; and then hit enter (or click &lt;em&gt;Run&lt;/em&gt;): 

  &lt;br /&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Macro" border="0" alt="Macro" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingExcelGame_1378A/image_9.png" width="375" height="358" /&gt;&lt;/p&gt;

&lt;p&gt;Well I have to say that I enjoyed playing with Excel. Maybe some day I’m going to use this for some serious thing or not &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Anyways... Happy hacking! 
  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9383568" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="Fun" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Fun/default.aspx" /><category term="Excel" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Excel/default.aspx" /></entry><entry><title>Attaching debugger to w3wp.exe using nice and easy keyboard shortcut</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/10/30/attaching-debugger-to-w3wp-exe-using-nice-and-easy-keyboard-shortcut.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/10/30/attaching-debugger-to-w3wp-exe-using-nice-and-easy-keyboard-shortcut.aspx</id><published>2008-10-30T22:56:43Z</published><updated>2008-10-30T22:56:43Z</updated><content type="html">&lt;p&gt;How many times have you done some web development and used following method to attach your Visual Studio Debugger to &lt;em&gt;w3wp.exe &lt;/em&gt;(a.k.a. &lt;em&gt;Debug &amp;gt; Attach to Process&lt;/em&gt; –method):    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_7.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_2.png" width="248" height="164" /&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;And then you scroll the long list and find your &lt;em&gt;w3wp.exe&lt;/em&gt; and press attach:    &lt;br /&gt;&lt;a target="_blank" href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/VSDebugger_2.png"&gt;&lt;img title="VSDebugger" border="0" alt="VSDebugger" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/VSDebugger_thumb.png" width="550" height="381" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’ll bet that you have done that a lot &lt;strong&gt;:-)&lt;/strong&gt; At least I have.    &lt;br /&gt;    &lt;br /&gt;Let’s create macro that does that very same thing but so that you don’t have to take your fingers of the keyboard.     &lt;br /&gt;First open up &lt;em&gt;Macro Explorer&lt;/em&gt; (using &lt;em&gt;View &amp;gt;&lt;/em&gt; &lt;em&gt;Other windows&lt;/em&gt; &amp;gt; &lt;em&gt;Macro Explorer&lt;/em&gt; or just hit &lt;em&gt;Alt-F8&lt;/em&gt;). Then open up example &lt;em&gt;AttachToCalc &lt;/em&gt;macro under &lt;em&gt;Samples &lt;/em&gt;&amp;gt; &lt;em&gt;VSDebugger&lt;/em&gt;:    &lt;br /&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_3.png" width="198" height="215" /&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;Right click and select edit:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_9.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_3.png" width="210" height="142" /&gt;&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;Copy contents of that and create new macro under &lt;em&gt;My Macros&lt;/em&gt;:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_11.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_4.png" width="258" height="108" /&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;And give it a name &lt;em&gt;MyVSDebugger&lt;/em&gt;. Then paste the source code to it. Then modify the process name from &lt;em&gt;calc.exe&lt;/em&gt; to &lt;em&gt;w3wp.exe&lt;/em&gt; and remove the &lt;em&gt;Exit For&lt;/em&gt;. You should have something like this left:&lt;/p&gt;  &lt;p&gt;   &lt;table cellspacing="10"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" align="right"&gt;           &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; System
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; EnvDTE
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; EnvDTE80
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; EnvDTE90
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; System.Diagnostics

&lt;font color="#0000ff"&gt;Public&lt;/font&gt; &lt;font color="#0000ff"&gt;Module&lt;/font&gt; MyVSDebugger

  &lt;font color="#008000"&gt;' This subroutine attaches to w3wp.exe:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Sub&lt;/font&gt; AttachToW3WP()
    &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; attached &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Boolean&lt;/font&gt; = &lt;font color="#0000ff"&gt;False
&lt;/font&gt;    &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; proc &lt;font color="#0000ff"&gt;As&lt;/font&gt; EnvDTE.Process

    &lt;font color="#0000ff"&gt;For&lt;/font&gt; &lt;font color="#0000ff"&gt;Each&lt;/font&gt; proc &lt;font color="#0000ff"&gt;In&lt;/font&gt; DTE.Debugger.LocalProcesses
      &lt;font color="#0000ff"&gt;If&lt;/font&gt; (Right(proc.Name, 8) = &lt;font color="#a31515"&gt;&amp;quot;w3wp.exe&amp;quot;&lt;/font&gt;) &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;        proc.Attach()
        attached = &lt;font color="#0000ff"&gt;True
&lt;/font&gt;      &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;    &lt;font color="#0000ff"&gt;Next

&lt;/font&gt;    &lt;font color="#0000ff"&gt;If&lt;/font&gt; attached = &lt;font color="#0000ff"&gt;False&lt;/font&gt; &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;      MsgBox(&lt;font color="#a31515"&gt;&amp;quot;Couldn't find w3wp.exe&amp;quot;&lt;/font&gt;)
    &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If

&lt;/font&gt;  &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub

End&lt;/font&gt; &lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
Now you should have this kind of view at the &lt;em&gt;Macro Explorer&lt;/em&gt;:

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_5.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_1.png" width="176" height="123" /&gt;&lt;/a&gt;

  &lt;br /&gt;

  &lt;br /&gt;Now let’s add keyboard shortcut for our macro from &lt;em&gt;Tools&lt;/em&gt; &amp;gt; &lt;em&gt;Options&lt;/em&gt; and &lt;em&gt;Environment &lt;/em&gt;&amp;gt; &lt;em&gt;Keyboard&lt;/em&gt;:

  &lt;br /&gt;&lt;a target="_blank" href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_13.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_5.png" width="646" height="377" /&gt;&lt;/a&gt; 

  &lt;br /&gt;Just find your new macro and set focus to &lt;em&gt;Press shortcut keys&lt;/em&gt; field and press your favorite keyboard shortcut and press &lt;em&gt;Assign&lt;/em&gt; and then press &lt;em&gt;OK&lt;/em&gt;. &lt;strong&gt;NOTE:&lt;/strong&gt; You might have another command already using that combination but you can override it if you like.&lt;/p&gt;

&lt;p&gt;Now we’re ready to use that. If you want to build your solution you can Ctrl-Shift-B and if you want to attach to &lt;em&gt;w3wp.exe &lt;/em&gt;you’ll just press &lt;em&gt;Ctrl-Shift-V. &lt;/em&gt;This is extremely handy if you have &lt;em&gt;Post-Build event&lt;/em&gt; nicely set.

  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking!

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9025158" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="asp.net" scheme="http://blogs.msdn.com/jannemattila/archive/tags/asp.net/default.aspx" /><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /><category term="Visual Studio" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Visual+Studio/default.aspx" /></entry><entry><title>Web Services and namespaces (or WCF?)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/10/15/web-services-and-namespaces-or-wcf.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/10/15/web-services-and-namespaces-or-wcf.aspx</id><published>2008-10-15T10:27:28Z</published><updated>2008-10-15T10:27:28Z</updated><content type="html">&lt;p&gt;You might have encountered following situation:    &lt;br /&gt;1. You have created class library “MyLibrary” and it contains following class:     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;   &lt;table cellspacing="10"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" align="right"&gt;           &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; MyLibrary
{
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;Employee
&lt;/font&gt;  {
    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt; FirstName;
    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;string&lt;/font&gt; LastName;
  }
}&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;2. You have created Web Service “MyWeb” using following VS template: 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/Web%20Service%20project_2.png"&gt;&lt;img title="Web Service project" border="0" alt="Web Service project" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/Web%20Service%20project_thumb.png" width="128" height="20" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&amp;#160; - It references “MyLibrary” 

  &lt;br /&gt;&amp;#160; - It contains following method: &lt;/p&gt;

&lt;p&gt;
  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;MyWeb&lt;/font&gt; : System.Web.Services.&lt;font color="#2b91af"&gt;WebService
&lt;/font&gt;{
  [&lt;font color="#2b91af"&gt;WebMethod&lt;/font&gt;]
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; AddNewEmployee(MyLibrary.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee)
  {
    &lt;font color="#008000"&gt;// TODO: implement
&lt;/font&gt;  }
}&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;3. Finally you create Windows Forms application “My Win App”: 
  &lt;br /&gt;&amp;#160; - You “Add Web Reference” to “MyWeb” and you name it “WebServices” 

  &lt;br /&gt;&amp;#160; - You write following code to use that web service: &lt;/p&gt;

&lt;p&gt;
  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;WebServices.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee = &lt;font color="#0000ff"&gt;new&lt;/font&gt; WebServices.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt;();
employee.FirstName = &lt;font color="#a31515"&gt;&amp;quot;John&amp;quot;&lt;/font&gt;;
employee.LastName = &lt;font color="#a31515"&gt;&amp;quot;Doe&amp;quot;&lt;/font&gt;;
WebServices.&lt;font color="#2b91af"&gt;MyWeb&lt;/font&gt; myWeb = &lt;font color="#0000ff"&gt;new&lt;/font&gt; WebServices.&lt;font color="#2b91af"&gt;MyWeb&lt;/font&gt;();
myWeb.AddNewEmployee(employee);&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;4. You run your application and all is fine. 
  &lt;br /&gt;5. Later you notice that you need to add reference to your “MyLibrary” into your “My Win App” 

  &lt;br /&gt;(There could be many reasons for this. For example you want to use same business logic that web service uses etc.) 

  &lt;br /&gt;6. You add following code to you “My Win App”: &lt;/p&gt;

&lt;p&gt;
  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;MyLibrary.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee2 = &lt;font color="#0000ff"&gt;new&lt;/font&gt; MyLibrary.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt;();
MyLibrary.&lt;font color="#2b91af"&gt;EmployeeManager&lt;/font&gt; employeeManager = &lt;font color="#0000ff"&gt;new&lt;/font&gt; MyLibrary.&lt;font color="#2b91af"&gt;EmployeeManager&lt;/font&gt;();
employeeManager.AddNewEmployee(employee2);&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;7. Code works fine but then you notice that you actually have the same class from two different namespaces. What if you try to mix and match them (and sometimes you just have to do that)? Let’s see what happens:&lt;/p&gt;

&lt;p&gt;
  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;WebServices.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee = &lt;font color="#0000ff"&gt;new&lt;/font&gt; WebServices.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt;();
MyLibrary.&lt;font color="#2b91af"&gt;EmployeeManager&lt;/font&gt; employeeManager = &lt;font color="#0000ff"&gt;new&lt;/font&gt; MyLibrary.&lt;font color="#2b91af"&gt;EmployeeManager&lt;/font&gt;();
employeeManager.AddNewEmployee(employee);&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;8. When you try to compile your application and you’ll receive following error: 
  &lt;br /&gt;&lt;em&gt;&lt;img title="VS compile error" border="0" alt="VS compile error" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/VS%20compile%20error_3.png" width="703" height="62" /&gt;&amp;#160; Error&amp;#160;&amp;#160;&amp;#160; 11&amp;#160;&amp;#160;&amp;#160; The best overloaded method match for 'MyLibrary.EmployeeManager.AddNewEmployee(MyLibrary.Employee)' has some invalid arguments&amp;#160;&amp;#160;&amp;#160; C:\&amp;lt;path&amp;gt;\MyWinApp\MainForm.cs&amp;#160;&amp;#160;&amp;#160; 41&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160; MyWinApp 

    &lt;br /&gt;Error&amp;#160;&amp;#160;&amp;#160; 12&amp;#160;&amp;#160;&amp;#160; Argument '1': cannot convert from 'MyWinApp.WebServices.Employee' to 'MyLibrary.Employee'&amp;#160;&amp;#160;&amp;#160; C:\&amp;lt;path&amp;gt;\MyWinApp\MainForm.cs&amp;#160;&amp;#160;&amp;#160; 41&amp;#160;&amp;#160;&amp;#160; 32&amp;#160;&amp;#160;&amp;#160; MyWinApp 

    &lt;br /&gt;&lt;/em&gt;

  &lt;br /&gt;9. You open up the generated proxy code: 

  &lt;br /&gt;&lt;img title="Reference" border="0" alt="Reference" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/Reference_3.png" width="172" height="97" /&gt; 

  &lt;br /&gt;

  &lt;br /&gt;10. You locate the code where &lt;em&gt;Employee&lt;/em&gt; is defined and comment that part. And then you compile again with following results: 

  &lt;br /&gt;&lt;em&gt;Error&amp;#160;&amp;#160;&amp;#160; 11&amp;#160;&amp;#160;&amp;#160; The type or namespace name 'Employee' could not be found (are you missing a using directive or an assembly reference?)&amp;#160;&amp;#160;&amp;#160; C:\&amp;lt;path&amp;gt;\MyWinApp\Web References\WebServices\Reference.cs&amp;#160;&amp;#160;&amp;#160; 82&amp;#160;&amp;#160;&amp;#160; 36&amp;#160;&amp;#160;&amp;#160; MyWinApp 
    &lt;br /&gt;&lt;/em&gt;

  &lt;br /&gt;11. You fix that by resolving the missing type: 

  &lt;br /&gt;&lt;img title="VS Resolve" border="0" alt="VS Resolve" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/VS%20Resolve_3.png" width="518" height="66" /&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;12. You compile and you’re happy right (obviously you need to modify also all &lt;em&gt;WebServices.Employee&lt;/em&gt; types to &lt;em&gt;MyLibrary.Employee&lt;/em&gt; types)?&lt;/p&gt;

&lt;p&gt;Well you might be happy since now your code works... &lt;strong&gt;BUT&lt;/strong&gt; you have manually edited generated file which will be re-generated every time you do “Update Web Reference” from Visual Studio and you’ll lose you modifications. And that’s not nice.&lt;/p&gt;

&lt;p&gt;If this would be question for me I would give you following answer (you might find different opinions on this one): Go to the WCF route instead &lt;strong&gt;:-) &lt;/strong&gt;If Windows Communication Foundation (WCF) is something new to you I think you should check these out and find more information on the web: &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation"&gt;Overview of WCF from Wikipedia&lt;/a&gt; and &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx"&gt;Windows Communication Foundation home on MSDN&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;I’m going to run through this same example with WCF way and then we can (hopefully) see why it fits like good glove.&lt;/p&gt;

&lt;p&gt;1. Create new WCF project called “MyWcf” using following VS template: 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/WCF%201_2.png"&gt;&lt;img title="WCF 1" border="0" alt="WCF 1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/WCF%201_thumb.png" width="138" height="18" /&gt;&lt;/a&gt; 

  &lt;br /&gt;2. Add reference to “MyLibrary” 

  &lt;br /&gt;3. Delete &lt;em&gt;IService1.cs&lt;/em&gt; and &lt;em&gt;Service1.svc &lt;/em&gt;from your newly created project. 

  &lt;br /&gt;4. Add new item “MyWcfService.svc” (using &lt;em&gt;WCF Service &lt;/em&gt;template) 

  &lt;br /&gt;5. Modify “IMyWcfService.cs” file: 

  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.ServiceModel;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; MyLibrary;

&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; MyWcf
{
  [&lt;font color="#2b91af"&gt;ServiceContract&lt;/font&gt;]
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;interface&lt;/font&gt; &lt;font color="#2b91af"&gt;IMyWcfService
&lt;/font&gt;  {
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;]
    &lt;font color="#0000ff"&gt;void&lt;/font&gt; AddNewEmployee(&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee);
  }
}&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
6. Modify “MyWcfService.cs” file: 

  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; MyLibrary;

&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; MyWcf
{
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;MyWcfService&lt;/font&gt; : &lt;font color="#2b91af"&gt;IMyWcfService
&lt;/font&gt;  {
    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; AddNewEmployee(&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee)
    {
      &lt;font color="#008000"&gt;// TODO: implement
&lt;/font&gt;    }
  }
}&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
7. Open up “web.config” and modify the &lt;em&gt;system.serviceModel&lt;/em&gt; section as follows: 

  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;system.serviceModel&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;services&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;service&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;behaviorConfiguration&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;MyWcf.MyWcfServiceBehavior&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;MyWcf.MyWcfService&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;&amp;gt;
   &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;endpoint&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;address&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&amp;quot;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;binding&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;basicHttpBinding&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;contract&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;MyWcf.IMyWcfService&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;identity&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
     &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;dns&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;value&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;localhost&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; /&amp;gt;
    &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;identity&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
   &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;endpoint&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
   &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;endpoint&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;address&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;mex&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;binding&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;mexHttpBinding&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;contract&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;IMetadataExchange&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; /&amp;gt;
  &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;service&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;services&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;behaviors&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;serviceBehaviors&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
   &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;behavior&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;MyWcf.MyWcfServiceBehavior&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;serviceMetadata&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;httpGetEnabled&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;true&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; /&amp;gt;
    &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;serviceDebug&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;includeExceptionDetailInFaults&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;false&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; /&amp;gt;
   &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;behavior&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;serviceBehaviors&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
 &amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;behaviors&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;system.serviceModel&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
(you might notice that most important part is the &lt;strong&gt;binding&lt;em&gt; &lt;/em&gt;&lt;/strong&gt;what I have changed to be &lt;strong&gt;basicHttpBinding&lt;/strong&gt;) 

  &lt;br /&gt;

  &lt;br /&gt;8. Go back to your “My Win App” project. 

  &lt;br /&gt;&amp;#160; - Remove “WebServices” web references 

  &lt;br /&gt;&amp;#160; - Add new “Service Reference” to your newly created WCF Service and name it “WcfServices” 

  &lt;br /&gt;&amp;#160; - Verify that you have “Reuse types in referenced assemblies” checked in settings (you can see them if you click &lt;em&gt;Advanced...&lt;/em&gt; button from the “&lt;em&gt;Add Service Reference”&lt;/em&gt; dialog): 

  &lt;br /&gt;&lt;img title="WCF 2" border="0" alt="WCF 2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/WhyWCFsinceIlikeWebServices_78D2/WCF%202_3.png" width="287" height="256" /&gt;&amp;#160; &lt;br /&gt;

  &lt;br /&gt;9. Modify your code to use this new service: 

  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;MyLibrary.&lt;font color="#2b91af"&gt;Employee&lt;/font&gt; employee = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;Employee&lt;/font&gt;();
employee.FirstName = &lt;font color="#a31515"&gt;&amp;quot;John&amp;quot;&lt;/font&gt;;
employee.LastName = &lt;font color="#a31515"&gt;&amp;quot;Doe&amp;quot;&lt;/font&gt;;
WcfServices.&lt;font color="#2b91af"&gt;MyWcfServiceClient&lt;/font&gt; myWcf = &lt;font color="#0000ff"&gt;new&lt;/font&gt; MyWinApp.WcfServices.&lt;font color="#2b91af"&gt;MyWcfServiceClient&lt;/font&gt;();
myWcf.AddNewEmployee(employee);&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
10. Enjoy one of the benefits of WCF &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is just one of the many benefits that WCF over the “good old ASP.NET Web Services”. So if you’re interested then you should start looking more information on the web. 
  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking! 

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9000423" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term=".NET General" scheme="http://blogs.msdn.com/jannemattila/archive/tags/.NET+General/default.aspx" /><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="WCF" scheme="http://blogs.msdn.com/jannemattila/archive/tags/WCF/default.aspx" /></entry><entry><title>Tip: Disable RunOnce from Internet Explorer in your VPC images</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/09/17/tip-disable-runonce-from-internet-explorer-in-your-vpc-images.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/09/17/tip-disable-runonce-from-internet-explorer-in-your-vpc-images.aspx</id><published>2008-09-17T14:30:37Z</published><updated>2008-09-17T14:30:37Z</updated><content type="html">&lt;p&gt;If you’re working with VPC images that cannot connect to internet you might have noticed annoying thing at Internet Explorer. IE tries to connect to internet so that it could finish up the setup. It’s good if you &lt;strong&gt;CAN&lt;/strong&gt; connect to internet but it’s really annoying if you won’t ever have network connection (and this happens typically if you don’t want to connect your VPC to network). And waiting for the timeout isn’t that nice (+ pressing the stop button doesn’t help that much).&lt;/p&gt;  &lt;p&gt;This can be however changed through registry. Just add two keys (or modify existing) &lt;em&gt;RunOnceHasShown&lt;/em&gt; and &lt;em&gt;RunOnceComplete&lt;/em&gt;. Here is example .reg file for that:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Windows Registry Editor Version 5.00 &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]     &lt;br /&gt;&amp;quot;RunOnceHasShown&amp;quot;=dword:00000001      &lt;br /&gt;&amp;quot;RunOnceComplete&amp;quot;=dword:00000001&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;After that you should have following keys under &lt;em&gt;HKCU\Software\Microsoft\Internet Explorer\Main&lt;/em&gt;:&lt;/p&gt;  &lt;p&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/DisableRunOncefromInternetExplorer_C3BE/image_3.png" width="336" height="48" /&gt;&lt;/p&gt;  &lt;p&gt;And now if you launch IE it won’t try to connect to internet. You might also want to change your home page to be something simple like &lt;em&gt;about:blank&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;This was just small tip to make your development life a bit easier in the world of VPC images.   &lt;br /&gt;    &lt;br /&gt;Anyways… Happy hacking!    &lt;br /&gt;    &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8955348" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /></entry><entry><title>Use LINQ to access CRM objects</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/08/29/use-linq-to-access-crm-objects.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/08/29/use-linq-to-access-crm-objects.aspx</id><published>2008-08-29T15:43:07Z</published><updated>2008-08-29T15:43:07Z</updated><content type="html">&lt;p&gt;&lt;/p&gt;  &lt;p&gt;If you have written small console application to check some data from CRM database you have probably already read this article from MSDN: &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/cc151204.aspx"&gt;Use Filtered Views&lt;/a&gt;. That is okay but honestly I’m currently more into LINQ solution. I’ll show you what I mean...&lt;/p&gt;  &lt;p&gt;First I'll create new Console Application project and &lt;em&gt;Add New Item&lt;/em&gt; to it and select &lt;em&gt;LINQ to SQL Classes&lt;/em&gt; and name it &lt;em&gt;CRMDataClasses.dbml&lt;/em&gt;:     &lt;br /&gt;&lt;img title="LINQDataClasses" border="0" alt="LINQDataClasses" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CRMandLINQ_C741/LINQDataClasses_3.png" width="544" height="304" /&gt; &lt;/p&gt;  &lt;p&gt;Then I'll use &lt;em&gt;Server Explorer&lt;/em&gt; to connect to CRM database:     &lt;br /&gt;&lt;img title="ServerExplorer" border="0" alt="ServerExplorer" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CRMandLINQ_C741/ServerExplorer_3.png" width="254" height="164" /&gt;&lt;/p&gt;  &lt;p&gt;And then I'll drag &lt;em&gt;Account, Contact, FilteredAccount &lt;/em&gt;and &lt;em&gt;FilteredContact&lt;/em&gt; to the canvas of our newly created &lt;em&gt;CRMDataClasses.dbml: &lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CRMandLINQ_C741/CRMDataClasses_5.png"&gt;&lt;img title="CRMDataClasses" border="0" alt="CRMDataClasses" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CRMandLINQ_C741/CRMDataClasses_thumb_1.png" width="700" height="264" /&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Now I'm ready to use LINQ to these views:    &lt;br /&gt;    &lt;table cellspacing="10"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" align="right"&gt;           &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#2b91af"&gt;CRMDataClassesDataContext&lt;/font&gt; dataContext = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;CRMDataClassesDataContext&lt;/font&gt;();

&lt;font color="#0000ff"&gt;var&lt;/font&gt; queryContact = &lt;font color="#0000ff"&gt;from&lt;/font&gt; contact &lt;font color="#0000ff"&gt;in&lt;/font&gt; dataContext.Contacts
          &lt;font color="#0000ff"&gt;where&lt;/font&gt; contact.MobilePhone.Length &amp;gt; 0 &amp;amp;&amp;amp;
          contact.LastName.Length &amp;gt; 0
    &lt;font color="#0000ff"&gt;select&lt;/font&gt; contact;

&lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(&lt;font color="#a31515"&gt;&amp;quot;Contact(s):&amp;quot;&lt;/font&gt;);
&lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#2b91af"&gt;Contact&lt;/font&gt; c &lt;font color="#0000ff"&gt;in&lt;/font&gt; queryContact)
{
  &lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(c.FirstName + &lt;font color="#a31515"&gt;&amp;quot; &amp;quot;&lt;/font&gt; + c.LastName + &lt;font color="#a31515"&gt;&amp;quot;, &amp;quot;&lt;/font&gt; + c.MobilePhone);
}

&lt;font color="#0000ff"&gt;var&lt;/font&gt; queryFilteredContact = &lt;font color="#0000ff"&gt;from&lt;/font&gt; contact &lt;font color="#0000ff"&gt;in&lt;/font&gt; dataContext.FilteredContacts
          &lt;font color="#0000ff"&gt;select&lt;/font&gt; contact;
&lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(&lt;font color="#a31515"&gt;&amp;quot;&amp;quot;&lt;/font&gt;);

&lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(&lt;font color="#a31515"&gt;&amp;quot;Filtered contact(s):&amp;quot;&lt;/font&gt;);
&lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#2b91af"&gt;FilteredContact&lt;/font&gt; c &lt;font color="#0000ff"&gt;in&lt;/font&gt; queryFilteredContact)
{
  &lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(c.lastname);
}&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;On lines 3 to 6 I queried all contacts that have lastname and mobilephone filled in. On lines 14 to 15 I'm querying all contacts where current user has access to. &lt;strong&gt;NOTE: It doesn't return anything if you use SQL Authentication!&lt;/strong&gt; So both of these can be used to fill you applications needs. But do notice that for some reason the attributes at the &lt;em&gt;FilteredContacts&lt;/em&gt; are all lower case and in &lt;em&gt;Contacts&lt;/em&gt; their naming is a bit different. So if you plan to change from &lt;em&gt;Contacts &lt;/em&gt;to &lt;em&gt;FilteredContact&lt;/em&gt; your going to have to change the casing of the attributes little bit.&lt;/p&gt;

&lt;p&gt;This was just quick advice how you can leverage LINQ to your CRM solutions.
  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking!

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8904857" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="Microsoft CRM" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+CRM/default.aspx" /></entry><entry><title>Maximize the use of CPU with parallel extensions (+ some WPF stuff)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/08/26/maximize-the-use-of-cpu-with-parallel-extensions-some-wpf-stuff.aspx" /><link rel="enclosure" type="video/x-ms-wmv" length="18623" href="http://blogs.msdn.com/jannemattila/attachment/8898129.ashx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/08/26/maximize-the-use-of-cpu-with-parallel-extensions-some-wpf-stuff.aspx</id><published>2008-08-26T22:03:00Z</published><updated>2008-08-26T22:03:00Z</updated><content type="html">&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Since this is my &lt;u&gt;40th post to this blog&lt;/u&gt; I decided to go back to square one… or &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/01/07/solving-small-puzzles-with-just-a-few-lines-of-code.aspx" target="_blank"&gt;post one&lt;/a&gt; actually &lt;strong&gt;:-)&lt;/strong&gt; I’m going to create Windows Presentation Foundation (WPF) application that solves the &lt;a href="http://en.wikipedia.org/wiki/Knight%27s_tour" target="_blank"&gt;Knight’s Tour&lt;/a&gt; puzzle. I actually didn’t know about this puzzle before I bought book called &lt;a href="http://www.wrox.com/WileyCDA/WroxTitle/Puzzles-for-Programmers-and-Pros.productCd-0470121688.html" target="_blank"&gt;Puzzles for Programmers and Pros&lt;/a&gt;. That book had interesting puzzle that lead in to this post. So here we go!&lt;/p&gt;  &lt;p&gt;I said that I’m going to create WPF application for my UI. You might ask why not the “good old” Windows Forms application...? Well for these simple reasons:    &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;1.&lt;/strong&gt;&amp;#160; I don’t like to write code to &lt;em&gt;OnPaint&lt;/em&gt; / &lt;em&gt;MainForm_Paint&lt;/em&gt; methods.     &lt;br /&gt;&lt;strong&gt;2. &lt;/strong&gt;I wanted to define my user interface and then just say in code “hey knight go there” and it should just draw the UI with the knight in the correct position. But the defined UI must be also scalable.     &lt;br /&gt;&lt;strong&gt;3. &lt;/strong&gt;WPF doesn’t have same barriers than Windows Forms does =&amp;gt; It’s the face of future applications!     &lt;br /&gt;    &lt;br /&gt;I don’t probably have to explain my reason #1 for you if you have experienced the same that I have :-) You’ll end up writing the UI code a lot and that’s not what you’re trying to do. You’re trying to solve puzzle and you are suddenly focusing for the UI code. That’s wrong approach. Therefore reason #2 goes hand-in-hand with #1. &lt;/p&gt;  &lt;p&gt;So let’s look the the UI of the running application:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/KnightsTourparallelism_CDDE/WPF%20UI_2.png"&gt;&lt;img title="WPF UI" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="306" alt="WPF UI" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/KnightsTourparallelism_CDDE/WPF%20UI_thumb.png" width="306" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It’s the view of the classic chess board and I decided to take shortcut when creating the knight. I decided to use gray circle instead (or ellipse actually) &lt;strong&gt;:-)&lt;/strong&gt; And for the layout management I just took the easy approach by using &lt;em&gt;Grid&lt;/em&gt; and defining &lt;em&gt;Columns&lt;/em&gt; and &lt;em&gt;Rows&lt;/em&gt;. Here is the XAML for the UI:&lt;/p&gt;  &lt;table cellspacing="10"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" align="right"&gt;         &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top"&gt;
        &lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Window&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Class&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Window1&amp;quot;
&lt;/font&gt;  &lt;font color="#ff0000"&gt; xmlns&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
&lt;/font&gt;  &lt;font color="#ff0000"&gt; xmlns&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;x&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
&lt;/font&gt;  &lt;font color="#ff0000"&gt; Title&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Knight's Tour&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; MinHeight&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; MinWidth&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/font&gt; 
    &lt;font color="#ff0000"&gt; Width&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;300&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Height&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;300&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Loaded&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Window_Loaded&amp;quot;&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;  &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Grid&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Board&amp;quot;&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    
    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Grid.ColumnDefinitions&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ColumnDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Grid.ColumnDefinitions&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Grid.RowDefinitions&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;RowDefinition&lt;/font&gt;&lt;font color="#0000ff"&gt; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Grid.RowDefinitions&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;

&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Ellipse&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Knight&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Fill&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Gray&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Panel.ZIndex&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;1&amp;quot;
&lt;/font&gt;        &lt;font color="#ff0000"&gt; Grid.Column&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;{&lt;/font&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;font color="#ff0000"&gt; Path&lt;/font&gt;&lt;font color="#0000ff"&gt;=KnightX}&amp;quot;&lt;/font&gt; 
        &lt;font color="#ff0000"&gt; Grid.Row&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;{&lt;/font&gt;&lt;font color="#a31515"&gt;Binding&lt;/font&gt;&lt;font color="#ff0000"&gt; Path&lt;/font&gt;&lt;font color="#0000ff"&gt;=KnightY}&amp;quot; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    
    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Rectangle&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;A8&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Fill&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;White&amp;quot; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Rectangle&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;B8&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Grid.Column&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;1&amp;quot; /&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#008000"&gt;&amp;lt;!-- Etc... --&amp;gt;
&lt;/font&gt;&lt;font color="#a31515"&gt;  &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Grid&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Window&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;You probably noticed the interesting part of the XAML... and that’s the lines 30 and 31 where &lt;em&gt;Binding &lt;/em&gt;is defined. It means that these values coming from the public properties of the &lt;em&gt;DataContext&lt;/em&gt;. So let’s look at the code behind that XAML and let’s discuss the binding little bit more: 

  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.ComponentModel;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Diagnostics;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Windows;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Windows.Media;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Windows.Shapes;

&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;partial&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;Window1&lt;/font&gt; : &lt;font color="#2b91af"&gt;Window&lt;/font&gt;, &lt;font color="#2b91af"&gt;INotifyPropertyChanged
&lt;/font&gt;{
  &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; knightX = 0;
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; KnightX
  {
    &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; knightX; }
    &lt;font color="#0000ff"&gt;set
&lt;/font&gt;    {
      knightX = &lt;font color="#0000ff"&gt;value&lt;/font&gt;;
      NotifyPropertyChanged(&lt;font color="#a31515"&gt;&amp;quot;KnightX&amp;quot;&lt;/font&gt;);
    }
  }

  &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; knightY = 0;
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;int&lt;/font&gt; KnightY
  {
    &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; knightY; }
    &lt;font color="#0000ff"&gt;set
&lt;/font&gt;    {
      knightY = &lt;font color="#0000ff"&gt;value&lt;/font&gt;;
      NotifyPropertyChanged(&lt;font color="#a31515"&gt;&amp;quot;KnightY&amp;quot;&lt;/font&gt;);
    }
  }

  &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; Window_Loaded(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;font color="#2b91af"&gt;RoutedEventArgs&lt;/font&gt; e)
  {
    Knight.DataContext = &lt;font color="#0000ff"&gt;this&lt;/font&gt;;
    &lt;font color="#008000"&gt;// Now moving the Knight is easy!
&lt;/font&gt;    KnightX = 3;
    KnightY = 3;
  }

  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;event&lt;/font&gt; &lt;font color="#2b91af"&gt;PropertyChangedEventHandler&lt;/font&gt; PropertyChanged;
  &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; NotifyPropertyChanged(&lt;font color="#2b91af"&gt;String&lt;/font&gt; info)
  {
    &lt;font color="#0000ff"&gt;if&lt;/font&gt; (PropertyChanged != &lt;font color="#0000ff"&gt;null&lt;/font&gt;)
    {
      PropertyChanged(&lt;font color="#0000ff"&gt;this&lt;/font&gt;, &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;PropertyChangedEventArgs&lt;/font&gt;(info));
    }
  }
  &lt;font color="#008000"&gt;//...&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
You might already noticed that my window also implements &lt;em&gt;INotyfyPropertyChanged&lt;/em&gt; interface. And my two properties actually call &lt;em&gt;NotifyPropertyChanged&lt;/em&gt; method when they are changed. So what’s this all about? Well if you don’t do this your values will be updated for the first time and after that they don’t actually get “bubbled” up to the ellipse anymore... unless you implement the notify mechanisms yourself. This is quite important and you should probably read more information about it on MSDN. &lt;/p&gt;

&lt;p&gt;For the actual solving part I just used classic “old recursion” to solve the puzzle. And this is the part where we finally are going to the &lt;em&gt;title&lt;/em&gt; of my post... &lt;/p&gt;

&lt;p&gt;Classic one worker thread approach gives “fairly easy to implement but sub-optimal” solution. And you might ask why? And to answer this question I’m going so show you picture of task manager: 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/KnightsTourparallelism_CDDE/CPU1_2.png"&gt;&lt;img title="CPU1" height="116" alt="CPU1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/KnightsTourparallelism_CDDE/CPU1_thumb.png" width="654" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This picture was taken when my solver was running in “full speed ahead” –mode. And guess what... &lt;u&gt;I’m not impressed&lt;/u&gt;! I’m actually just using single CPU (see the third box where green line has reached the roof)!!! So my worker thread approach is far from optimal resource usage.&lt;/p&gt;

&lt;p&gt;Okay... What can I do then? I could do multiple threads and handle them manually but that’s again writing a lot of code that doesn’t have anything to do with the actual solving!? So if I would chosen Windows Forms + manual handling of multiple threads I would have a lot of code and just small fraction of that would actually do work that I was originally planning to do. &lt;/p&gt;

&lt;p&gt;This is where &lt;a href="http://blogs.msdn.com/pfxteam/" target="_blank"&gt;&lt;em&gt;Parallel Extensions&lt;/em&gt;&lt;/a&gt;&lt;em&gt; &lt;/em&gt;(&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3&amp;amp;displaylang=en" target="_blank"&gt;download&lt;/a&gt;)&lt;em&gt; &lt;/em&gt;comes into the game! It’s additional library (&lt;em&gt;System.Threading.dll&lt;/em&gt;) sitting on top of .NET Framework 3.5 and it’s currently in CTP phase. But I still highly recommend you to check it out if you want easily get more horse power to your algorithms. &lt;/p&gt;

&lt;p&gt;I analyzed my code and noticed part where I could do things differently: 
  &lt;table cellspacing="10"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" align="right"&gt;
          &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#008000"&gt;// My code was this:
&lt;/font&gt;&lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#0000ff"&gt;int&lt;/font&gt; location &lt;font color="#0000ff"&gt;in&lt;/font&gt; startLocations)
{
  &lt;font color="#008000"&gt;// Calculations here!
&lt;/font&gt;}

&lt;font color="#008000"&gt;// And I changed it to this:
&lt;/font&gt;&lt;font color="#2b91af"&gt;Parallel&lt;/font&gt;.ForEach&amp;lt;&lt;font color="#0000ff"&gt;int&lt;/font&gt;&amp;gt;(startLocations, (location) =&amp;gt;
{
  &lt;font color="#008000"&gt;// Calculations here!
&lt;/font&gt;});&lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;

  &lt;br /&gt;So I changed code in line 2 to be the code at line 8. What was the result at the task manager then: 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/KnightsTourparallelism_CDDE/CPU2_2.png"&gt;&lt;img title="CPU2" height="111" alt="CPU2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/KnightsTourparallelism_CDDE/CPU2_thumb.png" width="650" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Well I believe that I managed to get better use of the available horse power &lt;strong&gt;:-)&lt;/strong&gt; It shows of course in the results: 

  &lt;br /&gt;“foreach”: ~50 solved solutions in ~5 minutes 

  &lt;br /&gt;”Parallel.ForEach”: ~450 solved solutions in &amp;lt; 5 minutes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To summarize... &lt;/strong&gt;&lt;u&gt;I just changed 1 line of code and I was able to get unbelievable results from it!&lt;/u&gt; So if you’re doing something similar then I recommend checking out the parallel extensions first before doing “own custom solution” for that. &lt;/p&gt;

&lt;p&gt;I originally thought that I would go little bit deeper into the details of my solver but this post ended up too long even without it so maybe I’ll pass this time... But I’ll include &lt;a href="http://blogs.msdn.com/jannemattila/attachment/8898129.ashx" target="_blank"&gt;video clip&lt;/a&gt; that shows the UI of the application when it’s solving.

  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking! 

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;

&lt;p&gt;P.S. I’m also interested in F# and I’m probably going to do something fun with that too.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8898129" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term=".NET General" scheme="http://blogs.msdn.com/jannemattila/archive/tags/.NET+General/default.aspx" /><category term="Application Development" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Application+Development/default.aspx" /><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /></entry><entry><title>SQL Server Profiler and SPQuery</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/06/21/sql-server-profiler-and-spquery.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/06/21/sql-server-profiler-and-spquery.aspx</id><published>2008-06-21T22:58:08Z</published><updated>2008-06-21T22:58:08Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; I’m using SPQuery to retrieve items from my SharePoint list and now I want to know little bit more about SPQuery properties. Actually I’m interested about performance related things since I’m not sure about my query currently. I currently have following code to retrieve my data:&lt;br&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPSite&lt;/font&gt; site = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;SPSite&lt;/font&gt;(&lt;font color="#a31515"&gt;"http://mysharepoint"&lt;/font&gt;))
{
  &lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPWeb&lt;/font&gt; web = site.RootWeb)
  {
    &lt;font color="#2b91af"&gt;SPList&lt;/font&gt; docs = web.Lists[&lt;font color="#a31515"&gt;"MyDocs"&lt;/font&gt;];
    &lt;font color="#2b91af"&gt;SPQuery&lt;/font&gt; query = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;SPQuery&lt;/font&gt;();
    query.Query = &lt;font color="#a31515"&gt;@"&amp;lt;Query&amp;gt;
        &amp;lt;Where&amp;gt;
         &amp;lt;And&amp;gt;
           &amp;lt;Eq&amp;gt;
            &amp;lt;FieldRef Name='MyField' /&amp;gt;
            &amp;lt;Value Type='Text'&amp;gt;12345&amp;lt;/Value&amp;gt;
           &amp;lt;/Eq&amp;gt;
           &amp;lt;Eq&amp;gt;
            &amp;lt;FieldRef Name='ContentType' /&amp;gt;
            &amp;lt;Value Type='Text'&amp;gt;MyContentType&amp;lt;/Value&amp;gt;
           &amp;lt;/Eq&amp;gt;
         &amp;lt;/And&amp;gt;
        &amp;lt;/Where&amp;gt;
      &amp;lt;/Query&amp;gt;"&lt;/font&gt;;

    &lt;font color="#2b91af"&gt;SPListItemCollection&lt;/font&gt; items = docs.GetItems(query);
    &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#2b91af"&gt;SPListItem&lt;/font&gt; item &lt;font color="#0000ff"&gt;in&lt;/font&gt; items)
    {
      &lt;font color="#2b91af"&gt;Console&lt;/font&gt;.WriteLine(&lt;font color="#a31515"&gt;"Item: "&lt;/font&gt; + item.Title);
    }
  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Answer: &lt;/strong&gt;To answer this question I need to step into dark side for a minute... I mean that I’m going to ask you to play with SQL Server Profiler to analyze your query more closely. This is of course to give some ideas how to tune your query using query properties and nothing else. I don’t want you to start use any custom SQL queries or other weird hacks that you might come up. Just tune the query and that’s it. &lt;br&gt;&lt;strong&gt;NOTE: &lt;/strong&gt;&lt;u&gt;Do this stuff only in you own dev box&lt;/u&gt;. Don’t even think anything else. &lt;/p&gt;
&lt;p&gt;Before we start using the SQL Server Profiler you might want to stop SharePoint related services so that it’s easier to read the SQL trace. I’ve stopped &lt;em&gt;IIS Admin &lt;/em&gt;(+related), &lt;em&gt;Office SharePoint Server Search&lt;/em&gt; and &lt;em&gt;Windows SharePoint Services*&lt;/em&gt;. Now you can start SQL Server Profiler and you’re ready to start tracing. Just create new trace (File-&amp;gt;New Trace...) and select &lt;em&gt;Tuning&lt;/em&gt; for your template:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler1_2.png" target="_blank"&gt;&lt;img border="0" alt="SQLServerProfiler1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler1_thumb.png" width="640" height="404"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And if I now run your query I’ll get something like 200+ rows in my trace window. But you’re probably just interested for the rows that tell what is going on. If you pause the trace after the query then it’s most likely the last line in the grid:&lt;br&gt;&lt;img border="0" alt="SQLServerProfiler2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler2_068b6c0e-c3e1-4700-b280-ace6b48cf709.png" width="566" height="177"&gt;&amp;nbsp;&lt;br&gt;It gives you fairly long SQL (mine was ~4500 characters long) and it’s not trivial to understand what it is really doing. &lt;/p&gt;
&lt;p&gt;But first you probably notice the interesting&lt;em&gt;&amp;nbsp; SELECT TOP &lt;u&gt;2147483648&lt;/u&gt; ...&lt;/em&gt; And that’s the first thing you might want to change (of course you know best what you’re trying to achieve). But for that you have property called &lt;em&gt;RowLimit&lt;/em&gt;. So if you add “&lt;em&gt;query.RowLimit = 10;”&lt;/em&gt; to your code and re-run the trace you get following output:&lt;br&gt;&lt;img border="0" alt="SQLServerProfiler3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler3_c772bad8-4893-4c39-be9e-3f0f40c253d9.png" width="468" height="93"&gt;&amp;nbsp;&lt;br&gt;So now you have &lt;em&gt;SELECT TOP 11 ...&lt;/em&gt; which is better (note that the actual limit is your &lt;em&gt;RowLimit + 1&lt;/em&gt;). If you only need to display &lt;em&gt;n&lt;/em&gt; rows from database then don’t retrieve all and display just &lt;em&gt;n =&amp;gt; &lt;/em&gt;Use &lt;em&gt;RowLimit &lt;/em&gt;to narrow down the resultset.&lt;/p&gt;
&lt;p&gt;Next thing we need to take into consideration is &lt;em&gt;ViewFields&lt;/em&gt;. If I know that I’m only going to show &lt;em&gt;Title&lt;/em&gt;, then why should I need to retrieve more fields. Let’s narrow down the fields using &lt;em&gt;ViewFields&lt;/em&gt;:&lt;br&gt;
&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;query.ViewFields = &lt;font color="#a31515"&gt;@"&amp;lt;FieldRef Name='ID'/&amp;gt;
                     &amp;lt;FieldRef Name='Title'/&amp;gt;"&lt;/font&gt;;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;And again let’s test the trace and compare the query for the first trace. You may notice that the SQL is &lt;em&gt;only&lt;/em&gt; ~3000 chars long anymore and amount of columns at the resultset is a lot less (screenshot from management studio when both queries have been executed):&lt;br&gt;&lt;img border="0" alt="SQLServerProfiler4" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SQLProfilerandSQQuery_11109/SQLServerProfiler4_74dcdd16-91ed-4f65-9b7d-7fb9e23e54d9.png" width="384" height="207"&gt;&amp;nbsp;&lt;br&gt;Notice the size of scrollbar…. larger is better &lt;strong&gt;:-)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now I have just added few lines of code and the result is ~1500 shorter SQL and we’re only getting the amount of rows from DB that we need to. I’m not going to play with another properties but if you’re interested you might want to start with &lt;em&gt;Include*&lt;/em&gt; properties. &lt;/p&gt;
&lt;p&gt;I showed small example that how can use SQL Server toolset to verify (at least for some extend) that your queries are going for the right direction. &lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8633702" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Microsoft Office SharePoint Server 2007" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx" /><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /></entry><entry><title>Creating Localization Tool with Silverlight</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/06/08/creating-localization-tool-with-silverlight.aspx" /><link rel="enclosure" type="application/zip" length="240744" href="http://blogs.msdn.com/jannemattila/attachment/8580696.ashx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/06/08/creating-localization-tool-with-silverlight.aspx</id><published>2008-06-08T15:11:00Z</published><updated>2008-06-08T15:11:00Z</updated><content type="html">&lt;p&gt;Since &lt;a href="http://silverlight.net/GetStarted/" mce_href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight 2&lt;/a&gt; is in Beta 2 phase it’s definately time to create small application with it. Together with my &lt;a href="http://jarmoh.spaces.live.com/" mce_href="http://jarmoh.spaces.live.com/" target="_blank"&gt;friend&lt;/a&gt; we’e created small example application called &lt;i&gt;Localization Tool&lt;/i&gt;. Idea in our example application is pretty simple... allow end users to modify texts used in application. And for the end user it should be easy, intuitive and of course fast. We used a lot of information available from internet in order to help us in the implementation (see links at the end of this post). &lt;/p&gt; &lt;p&gt;Before going into implementation details you can check out the final solution in action (click the image to open video in new window):&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;a href="http://silverlight.services.live.com/invoke/48523/xEncoderApp0/iframe.html" title="Silverlight Localization Tool in action" mce_href="http://silverlight.services.live.com/invoke/48523/xEncoderApp0/iframe.html" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool_2141408c-2006-4e97-8f68-9ce334353abf.png" alt="Localization Tool" mce_src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool_2141408c-2006-4e97-8f68-9ce334353abf.png" border="0" height="361" width="640"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;In our solution we took WCF + LINQ + SQL approach and created following simple datatable:&lt;br&gt;&lt;img src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20table_f27bf6b5-aa8f-442e-b047-4d8321fd6f2c.png" alt="Localization Tool table" mce_src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20table_f27bf6b5-aa8f-442e-b047-4d8321fd6f2c.png" border="0" height="131" width="308"&gt; &lt;br&gt;That table is then used to store data like this:&lt;br&gt;&lt;img src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20table%20data_c9c96871-7919-46eb-8d31-6c0eb2e358a7.png" alt="Localization Tool table data" mce_src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20table%20data_c9c96871-7919-46eb-8d31-6c0eb2e358a7.png" border="0" height="149" width="485"&gt; &lt;br&gt;After that we’ve created LINQ to SQL data class for our table:&lt;br&gt;&lt;img src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20table%20data%20classes_33435a74-44f0-404b-a1fb-887b6b84e955.png" alt="Localization Tool table data classes" mce_src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20table%20data%20classes_33435a74-44f0-404b-a1fb-887b6b84e955.png" border="0" height="163" width="202"&gt; &lt;br&gt;Then we created service that provides data access to our localization table. All code behind that service is here:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="right" valign="top"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;br&gt;2&lt;br&gt;3&lt;br&gt;4&lt;br&gt;5&lt;br&gt;6&lt;br&gt;7&lt;br&gt;8&lt;br&gt;9&lt;br&gt;10&lt;br&gt;11&lt;br&gt;12&lt;br&gt;13&lt;br&gt;14&lt;br&gt;15&lt;br&gt;16&lt;br&gt;17&lt;br&gt;18&lt;br&gt;19&lt;br&gt;20&lt;br&gt;21&lt;br&gt;22&lt;br&gt;23&lt;br&gt;24&lt;br&gt;25&lt;br&gt;26&lt;br&gt;27&lt;br&gt;28&lt;br&gt;29&lt;br&gt;30&lt;br&gt;31&lt;br&gt;32&lt;br&gt;33&lt;br&gt;34&lt;br&gt;35&lt;br&gt;36&lt;br&gt;37&lt;br&gt;38&lt;br&gt;39&lt;br&gt;40&lt;br&gt;41&lt;br&gt;42&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;&lt;br&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Collections.Generic;&lt;br&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Linq;&lt;br&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; LocalizationTool_Web&lt;br&gt;{&lt;br&gt;  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;LocalizationService&lt;/font&gt; : &lt;font color="#2b91af"&gt;ILocalizationService&lt;br&gt;&lt;/font&gt;  {&lt;br&gt;    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#2b91af"&gt;List&lt;/font&gt;&amp;lt;&lt;font color="#2b91af"&gt;Localization&lt;/font&gt;&amp;gt; GetLocalizationByLanguage(&lt;font color="#0000ff"&gt;string&lt;/font&gt; language)&lt;br&gt;    {&lt;br&gt;      &lt;font color="#2b91af"&gt;LocalizationDataClassesDataContext&lt;/font&gt; dataContext = &lt;br&gt;        &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;LocalizationDataClassesDataContext&lt;/font&gt;();&lt;br&gt;      &lt;font color="#0000ff"&gt;var&lt;/font&gt; query = &lt;font color="#0000ff"&gt;from&lt;/font&gt; localization &lt;font color="#0000ff"&gt;in&lt;/font&gt; dataContext.Localizations&lt;br&gt;            &lt;font color="#0000ff"&gt;where&lt;/font&gt; localization.Language.Equals(language)&lt;br&gt;            &lt;font color="#0000ff"&gt;select&lt;/font&gt; localization;&lt;br&gt;      &lt;font color="#0000ff"&gt;return&lt;/font&gt; query.ToList();&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; UpdateLocalization(&lt;font color="#2b91af"&gt;Localization&lt;/font&gt; localization)&lt;br&gt;    {&lt;br&gt;      &lt;font color="#2b91af"&gt;LocalizationDataClassesDataContext&lt;/font&gt; dataContext = &lt;br&gt;        &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;LocalizationDataClassesDataContext&lt;/font&gt;();&lt;br&gt;      &lt;font color="#0000ff"&gt;var&lt;/font&gt; updateRow = dataContext.Localizations.First(&lt;br&gt;        loc =&amp;gt; &lt;br&gt;          loc.LanguageKey.Equals(localization.LanguageKey) &amp;amp;&amp;amp; &lt;br&gt;          loc.Language.Equals(localization.Language));&lt;br&gt;      updateRow.Text = localization.Text;&lt;br&gt;      updateRow.Comment = localization.Comment;&lt;br&gt;      dataContext.SubmitChanges();&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#2b91af"&gt;String&lt;/font&gt; [] GetLocales()&lt;br&gt;    {&lt;br&gt;      &lt;font color="#2b91af"&gt;LocalizationDataClassesDataContext&lt;/font&gt; dataContext = &lt;br&gt;        &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;LocalizationDataClassesDataContext&lt;/font&gt;();&lt;br&gt;      &lt;font color="#0000ff"&gt;var&lt;/font&gt; query = (&lt;font color="#0000ff"&gt;from&lt;/font&gt; localization &lt;font color="#0000ff"&gt;in&lt;/font&gt; dataContext.Localizations&lt;br&gt;             &lt;font color="#0000ff"&gt;select&lt;/font&gt; localization.Language).Distinct();&lt;br&gt;&lt;br&gt;      &lt;font color="#0000ff"&gt;return&lt;/font&gt; query.ToArray();&lt;br&gt;    }&lt;br&gt;  }&lt;br&gt;}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Now we’re ready to create UI for our application! We’ve used stackpanels for the layout management and then we used few &lt;i&gt;Style&lt;/i&gt; elements to make things look little bit better. &lt;br&gt;Here is small example about the styles in our &lt;i&gt;App.xaml&lt;/i&gt;:&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="right" valign="top"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;br&gt;2&lt;br&gt;3&lt;br&gt;4&lt;br&gt;5&lt;br&gt;6&lt;br&gt;7&lt;br&gt;8&lt;br&gt;9&lt;br&gt;10&lt;br&gt;11&lt;br&gt;12&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Application&lt;/font&gt;&lt;font color="#ff0000"&gt; xmlns&lt;/font&gt;&lt;font color="#0000ff"&gt;="http://schemas.microsoft.com/client/2007"&lt;br&gt;&lt;/font&gt;      &lt;font color="#ff0000"&gt; xmlns&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;x&lt;/font&gt;&lt;font color="#0000ff"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/font&gt; &lt;br&gt;      &lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Class&lt;/font&gt;&lt;font color="#0000ff"&gt;="LocalizationTool.App"&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;  &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Application.Resources&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;br&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Style&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Key&lt;/font&gt;&lt;font color="#0000ff"&gt;="Border"&lt;/font&gt;&lt;font color="#ff0000"&gt; TargetType&lt;/font&gt;&lt;font color="#0000ff"&gt;="Border"&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;="CornerRadius"&lt;/font&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;font color="#0000ff"&gt;="10"/&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;="Background"&lt;/font&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;font color="#0000ff"&gt;="#FFdedede"/&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;="VerticalAlignment"&lt;/font&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;font color="#0000ff"&gt;="Top"/&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;="Margin"&lt;/font&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;font color="#0000ff"&gt;="8,8,8,8"/&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Style&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&amp;lt;!-- ... and few more styles ... –&amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&lt;br&gt;At the &lt;i&gt;UserControl_Loaded&lt;/i&gt; we query for all the possible locales so that we can list them add the &lt;i&gt;ListBox.&lt;/i&gt; Here is the code for that (unfortunately the code looks terrible since it’s splitted into several rows only for display reasons):&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="right" valign="top"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;br&gt;2&lt;br&gt;3&lt;br&gt;4&lt;br&gt;5&lt;br&gt;6&lt;br&gt;7&lt;br&gt;8&lt;br&gt;9&lt;br&gt;10&lt;br&gt;11&lt;br&gt;12&lt;br&gt;13&lt;br&gt;14&lt;br&gt;15&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; UserControl_Loaded(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;font color="#2b91af"&gt;RoutedEventArgs&lt;/font&gt; e)&lt;br&gt;{&lt;br&gt;  LocalizationClientService.&lt;font color="#2b91af"&gt;LocalizationServiceClient&lt;/font&gt; client = &lt;br&gt;    &lt;font color="#0000ff"&gt;new&lt;/font&gt; LocalizationTool.LocalizationClientService.&lt;font color="#2b91af"&gt;LocalizationServiceClient&lt;/font&gt;();&lt;br&gt;  client.GetLocalesCompleted += &lt;br&gt;    &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;EventHandler&lt;/font&gt;&amp;lt;LocalizationClientService.&lt;font color="#2b91af"&gt;GetLocalesCompletedEventArgs&lt;/font&gt;&amp;gt;&lt;br&gt;      (client_GetLocalesCompleted);&lt;br&gt;  client.GetLocalesAsync();&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt; client_GetLocalesCompleted(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;br&gt;  LocalizationClientService.&lt;font color="#2b91af"&gt;GetLocalesCompletedEventArgs&lt;/font&gt; e)&lt;br&gt;{&lt;br&gt;  languages.ItemsSource = e.Result;&lt;br&gt;}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Using that same method we query all the localizations specific for that selected locale. There’s nothing fancy about that.. but let’s look at the search functionality little bit closer.&lt;br&gt;Our search button was defined like this in our &lt;i&gt;Page.xaml&lt;/i&gt;:&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="right" valign="top"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;br&gt;2&lt;br&gt;3&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;TextBox&lt;/font&gt;&lt;font color="#ff0000"&gt; Style&lt;/font&gt;&lt;font color="#0000ff"&gt;="{&lt;/font&gt;&lt;font color="#a31515"&gt;StaticResource&lt;/font&gt;&lt;font color="#ff0000"&gt; TextBox&lt;/font&gt;&lt;font color="#0000ff"&gt;}"&lt;/font&gt; &lt;br&gt;    &lt;font color="#ff0000"&gt; TextChanged&lt;/font&gt;&lt;font color="#0000ff"&gt;="searchCriteria_TextChanged"&lt;/font&gt; &lt;br&gt;    &lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;="searchCriteria" /&amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;And in our code behind we had following code to execute the query:&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="right" valign="top"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;br&gt;2&lt;br&gt;3&lt;br&gt;4&lt;br&gt;5&lt;br&gt;6&lt;br&gt;7&lt;br&gt;8&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#2b91af"&gt;String&lt;/font&gt; search = searchCriteria.Text.ToLower();&lt;br&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; query = &lt;font color="#0000ff"&gt;from&lt;/font&gt; row &lt;font color="#0000ff"&gt;in&lt;/font&gt; rows&lt;br&gt;      &lt;font color="#0000ff"&gt;where&lt;br&gt;&lt;/font&gt;        row.LanguageKey.ToLower().Contains(search) ||&lt;br&gt;        row.Text.ToLower().Contains(search) ||&lt;br&gt;        row.Comment.ToLower().Contains(search)&lt;br&gt;      &lt;font color="#0000ff"&gt;select&lt;/font&gt; row;&lt;br&gt;SetDatagridItemSource(query.ToArray());&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;And you can probably pretty easily see that actually that search box functionality doesn’t retrieve data from server at all. It uses the previously retrieved data (variable &lt;i&gt;rows&lt;/i&gt;) and filters out it by using linq. Therefore the performance is really good.&lt;/p&gt;
&lt;p&gt;We also added functionality to view two different languages at the same time. This helps to make the translations since the user can directly see what’s the equivalent row in another language. This was implemented withthe concept &lt;i&gt;base language. &lt;/i&gt;User can select what language he/she wants to use at the compare. Here’s example of that:&lt;br&gt;&lt;img src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20lock%20base%20language_f0b9535b-7415-4dbb-8df8-25c5f3fde44e.png" alt="Localization Tool lock base language" mce_src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/CreatingLocalizationToolwithSilverlight_195A/Localization%20Tool%20lock%20base%20language_f0b9535b-7415-4dbb-8df8-25c5f3fde44e.png" border="0" height="81" width="401"&gt;&amp;nbsp; &lt;br&gt;This was implemented by using the &lt;i&gt;RowDetails&lt;/i&gt; of datagrid. Here is the xaml of our datagrid:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;table cellspacing="10"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="right" valign="top"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1&lt;br&gt;2&lt;br&gt;3&lt;br&gt;4&lt;br&gt;5&lt;br&gt;6&lt;br&gt;7&lt;br&gt;8&lt;br&gt;9&lt;br&gt;10&lt;br&gt;11&lt;br&gt;12&lt;br&gt;13&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;System_Windows_Controls&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;DataGrid&lt;/font&gt; &lt;br&gt;  &lt;font color="#ff0000"&gt; AutoGenerateColumns&lt;/font&gt;&lt;font color="#0000ff"&gt;="True"&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;="resultsDatagrid"&lt;br&gt;&lt;/font&gt;  &lt;font color="#ff0000"&gt; Width&lt;/font&gt;&lt;font color="#0000ff"&gt;="770"&lt;/font&gt;&lt;font color="#ff0000"&gt; Height&lt;/font&gt;&lt;font color="#0000ff"&gt;="290"&lt;/font&gt;&lt;font color="#ff0000"&gt; Margin&lt;/font&gt;&lt;font color="#0000ff"&gt;="10,10,10,10"&lt;br&gt;&lt;/font&gt;  &lt;font color="#ff0000"&gt; CommittingEdit&lt;/font&gt;&lt;font color="#0000ff"&gt;="resultsDatagrid_CommittingEdit"&lt;br&gt;&lt;/font&gt;  &lt;font color="#ff0000"&gt; SelectionChanged&lt;/font&gt;&lt;font color="#0000ff"&gt;="resultsDatagrid_SelectionChanged"&lt;br&gt;&lt;/font&gt;  &lt;font color="#ff0000"&gt; LoadingRowDetails&lt;/font&gt;&lt;font color="#0000ff"&gt;="resultsDatagrid_LoadingRowDetails"&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;  &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;System_Windows_Controls&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;DataGrid.RowDetailsTemplate&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;DataTemplate&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;      &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;StackPanel&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;="tooltipPanel"&lt;/font&gt; &lt;br&gt;            &lt;font color="#ff0000"&gt; Orientation&lt;/font&gt;&lt;font color="#0000ff"&gt;="Horizontal"&lt;/font&gt;&lt;font color="#ff0000"&gt; Background&lt;/font&gt;&lt;font color="#0000ff"&gt;="LightYellow" /&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;DataTemplate&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#a31515"&gt;  &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;System_Windows_Controls&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;DataGrid.RowDetailsTemplate&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;br&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;System_Windows_Controls&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;DataGrid&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;And in &lt;i&gt;resultsDatagrid_LoadingRowDetails &lt;/i&gt;we just searched for the corresponding data row from our local base language array. If row was found then we dynamically created &lt;i&gt;TextBoxes&lt;/i&gt; to display the values of base language.&lt;/p&gt;
&lt;p&gt;This was just small example application that demonstrates the possibilities of Silverlight. Hopefully you got the idea that you can do pretty cool business applications with it.&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;
&lt;h3&gt;Links:&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://silverlight.net/GetStarted/" mce_href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight.Net - Getting started&lt;/a&gt;&lt;br&gt;&lt;a href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx" mce_href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx" target="_blank"&gt;Silverlight 2 Beta1 + WCF + LINQ to SQL = a powerfull combination&lt;/a&gt;&lt;br&gt;&lt;a href="http://silverlight.net/learn/tutorials/sqldatagrid.aspx" mce_href="http://silverlight.net/learn/tutorials/sqldatagrid.aspx" target="_blank"&gt;Displaying SQL Database Data in a DataGrid using LINQ and WCF&lt;/a&gt;&lt;br&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx" mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx" target="_blank"&gt;Scott Guthrie: Silverlight Tutorial Part 3: Using Networking to Retrieve Data and Populate a DataGrid&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8580696" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Programming" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx" /><category term="Silverlight" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Silverlight/default.aspx" /></entry><entry><title>Link: SharePoint slow spin-up times…</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jannemattila/archive/2008/05/29/link-sharepoint-slow-spin-up-times.aspx" /><id>http://blogs.msdn.com/jannemattila/archive/2008/05/29/link-sharepoint-slow-spin-up-times.aspx</id><published>2008-05-29T18:14:50Z</published><updated>2008-05-29T18:14:50Z</updated><content type="html">&lt;p&gt;I accidently found myself on this page: &lt;a href="http://jritmeijer.spaces.live.com/blog/cns!8A48A27460FB898A!965.entry" target="_blank"&gt;SharePoint 2007 Quirks - Solving painfully slow spin-up times&lt;/a&gt;. After reading that article I was forced to test that. And my &lt;em&gt;stsadm&lt;/em&gt; experience was really fast after that! So this link deserves a link post even if I don’t do those normally &lt;strong&gt;:-) &lt;/strong&gt;&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8558858" width="1" height="1"&gt;</content><author><name>jannemattila</name><uri>http://blogs.msdn.com/members/jannemattila.aspx</uri></author><category term="Microsoft Office SharePoint Server 2007" scheme="http://blogs.msdn.com/jannemattila/archive/tags/Microsoft+Office+SharePoint+Server+2007/default.aspx" /><category term="tips and tricks" scheme="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx" /></entry></feed>