<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Andrew Lynes' WebLog : .NET</title><link>http://blogs.msdn.com/anlynes/archive/tags/.NET/default.aspx</link><description>Tags: .NET</description><dc:language>en-AU</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Microsoft Certifications - Are they worth it?</title><link>http://blogs.msdn.com/anlynes/archive/2007/02/17/microsoft-certifications-are-they-worth-it.aspx</link><pubDate>Sat, 17 Feb 2007 00:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1691705</guid><dc:creator>anlynes</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/anlynes/comments/1691705.aspx</comments><wfw:commentRss>http://blogs.msdn.com/anlynes/commentrss.aspx?PostID=1691705</wfw:commentRss><description>&lt;P&gt;It's that time of year where I really need to move on my training objectives I set out at the beginning of year. In a rush of blood, I decided to update my .NET certifications to the latest and greatest. One question that comes up in discussions from time to time is whether it's worth the effort.&lt;/P&gt;
&lt;P&gt;In the best tradition of consultants, my response to this question is that "it all depends". Personally I don't see any point in going through the certification process simply to get a few letters after your name. I've interviewed enough people over the years with the Microsoft alphabet stapled to their resume who couldn't answer basic real world questions. Instead, the real goal of certification is to learn something. Of course in order to learn something, you may actually have to look at the exam material over a period of time rather than cram it in the night before. Although both strategies may see you certified, it is usually pretty clear in an interview/work situation who has&amp;nbsp;actually tried to improve their skills. So, if you're prepared to put in a bit of effort and learn something, I think certifications are worth it. However, if your goal is to be locked in a room for two hours to stare at a computer and eat lollies, you'd be better off staying at home and playing Age of Empires.&lt;/P&gt;
&lt;P&gt;For anyone still reading, my main tip for successfully getting certified is to go ahead and book the exam/s. Having a deadline is a great motivator to get on with it.&lt;/P&gt;
&lt;P&gt;Finally, for those that haven't looked for a while, the Microsoft Press training kits for the new MCPD and MCTS exams are now available from your favourite online bookstore.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1691705" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/anlynes/archive/tags/.NET/default.aspx">.NET</category></item><item><title>ASP.NET AJAX Ships</title><link>http://blogs.msdn.com/anlynes/archive/2007/01/24/asp-net-ajax-ships.aspx</link><pubDate>Wed, 24 Jan 2007 08:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1519711</guid><dc:creator>anlynes</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/anlynes/comments/1519711.aspx</comments><wfw:commentRss>http://blogs.msdn.com/anlynes/commentrss.aspx?PostID=1519711</wfw:commentRss><description>&lt;P&gt;This is great news. I've been waiting on this one for a while. I'm currently pondering what one of my major customer's application delivery methods might be in the future. This is another option to throw into the mix.&lt;/P&gt;
&lt;P&gt;Details can be found at &lt;A class="" href="http://ajax.asp.net/" mce_href="http://ajax.asp.net/"&gt;AJAX : The Official Microsoft ASP.NET AJAX Site&lt;/A&gt;&amp;nbsp;and &lt;A class="" href="http://weblogs.asp.net/scottgu" mce_href="http://weblogs.asp.net/scottgu"&gt;Scott Guthrie's blog&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1519711" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/anlynes/archive/tags/.NET/default.aspx">.NET</category></item><item><title>.NET and Auto-Restarting Services Revisited</title><link>http://blogs.msdn.com/anlynes/archive/2006/08/01/.NET-and-Auto_2D00_Restarting-Services-Revisited.aspx</link><pubDate>Tue, 01 Aug 2006 13:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:685126</guid><dc:creator>anlynes</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/anlynes/comments/685126.aspx</comments><wfw:commentRss>http://blogs.msdn.com/anlynes/commentrss.aspx?PostID=685126</wfw:commentRss><description>&lt;P&gt;Another follow-up post... I forgot to mention&amp;nbsp;that the numeric values for SC_ACTION_RESTART and SC_ACTION_REBOOT in the SC_ACTION_TYPE enumeration seem to be swapped in the documentation: &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sc_action_str.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sc_action_str.asp&lt;/A&gt;. I had to use the following declaration to get things to work as expected:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;enum SC_ACTION_TYPE : uint&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SC_ACTION_NONE = 0x00000000, // No action.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SC_ACTION_RESTART = 0x00000001, // Restart the service.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SC_ACTION_REBOOT = 0x00000002, // Reboot the computer.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SC_ACTION_RUN_COMMAND = 0x00000003 // Run a command.&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I also followed my own advice and cleaned up my mappings of managed and unmanaged data types in the attached file. There is (should be?) no functional difference from my previous post.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=685126" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/anlynes/attachment/685126.ashx" length="13807" type="text/plain" /><category domain="http://blogs.msdn.com/anlynes/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Using .NET Code to Set a Windows Service to Automatically Restart on Failure</title><link>http://blogs.msdn.com/anlynes/archive/2006/07/30/Using-.NET-Code-to-Set-a-Windows-Service-to-Automatically-Restart-on-Failure.aspx</link><pubDate>Sun, 30 Jul 2006 13:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:683192</guid><dc:creator>anlynes</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/anlynes/comments/683192.aspx</comments><wfw:commentRss>http://blogs.msdn.com/anlynes/commentrss.aspx?PostID=683192</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;This one popped up this week as I was investigating why a particular Windows service written in .NET 1.1 was terminating. After a quick MSN search, I only came up with a few fragments of C#, but not a complete solution. In attempting my own implementation, a few things came up that may be of interest to others.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;Firstly, the relevant Win32 API function is “ChangeServiceConfig2”. It’s a “jack of all trades” function, whose flexibility makes it a bit of a pain to call from .NET. The difficulty is that we need to pass it a structure that itself contains an array of&amp;nbsp;structures.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;Before getting to “ChangeServiceConfig2”, we first need to get a handle to the service via a call to the “OpenService” Win32 API function. It’s not mentioned in any documentation I’ve seen, but you need to request both SERVICE_CHANGE_CONFIG and SERVICE_START access rights, otherwise you’ll receive an “access denied” error from “ChangeServiceConfig2”.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;“OpenService” and “OpenSCManager” (which is also needed in the solution) return Windows handles. A common .NET misconception is that Windows handles should be treated as 32-bit integers (int, Int32 etc). In “unmanaged” land, the HANDLE type is actually a pointer to void (void*). This means IntPtr should be used to deal with these.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;The key structures for this task are SC_ACTION &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;and SERVICE_FAILURE_ACTIONS. The SC_ACTION structure describes what Windows should do in the event of a service failure. It is possible to provide serveral of these so that different actions can be taken on subsequent service failures. These all need to be placed into an array, which itself is then placed into SERVICE_FAILURE_ACTIONS (this is the pain mentioned above).&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT face="Courier New"&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;struct SC_ACTION&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[MarshalAs(UnmanagedType.U4)]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public SC_ACTION_TYPE Type;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[MarshalAs(UnmanagedType.U4)]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public UInt32 Delay;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;struct SERVICE_FAILURE_ACTIONS&amp;nbsp;&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[MarshalAs(UnmanagedType.U4)]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public UInt32 dwResetPeriod;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[MarshalAs(UnmanagedType.LPStr)]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public String lpRebootMsg;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[MarshalAs(UnmanagedType.LPStr)]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public String lpCommand;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[MarshalAs(UnmanagedType.U4)]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public UInt32 cActions;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public IntPtr lpsaActions;&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;In preparing the structures to pass to “ChangeServiceConfig2”, there is a requirement to perform pointer arithmetic in order to construct the array of failure actions. An arbitrary cast to a 32-bit integer would make the solution incompatible with 64-bit Windows. The safest option is to use Int64 for pointer arithmetic.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;Marshal.StructureToPtr(action2, (IntPtr)((Int64)actionPtr + Marshal.SizeOf(typeof(SC_ACTION))), false);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;After a bit of marshalling, we’re actually ready to call “ChangeServiceConfig2”. The good news is that this is straight forward. The only thing remaining is to handle any errors the .NET way.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;if (changeResult == 0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt"&gt;&lt;FONT face="Courier New"&gt;throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to change the Service configuration.");&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;Finally, since&amp;nbsp;we're working with unmanaged resources,&amp;nbsp;we need to make sure that things are cleaned up properly. The best pattern for this is to use a try-finally block.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;I’ve attached my first attempt at a solution, but it still needs testing on 64-bit platforms (fingers crossed). Note that under .NET 2.0, we would probably do a few things differently (such as make use of the new SafeHandle class). That said, the solution runs under .NET 2.0.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;BTW, for the security conscious, you should actually add a Link Demand to methods that that use the Marshal class. I’ll leave the details for another day, but your method will be exposed to certain types of security issues if you don’t.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Courier New"&gt;[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=683192" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/anlynes/attachment/683192.ashx" length="13660" type="text/plain" /><category domain="http://blogs.msdn.com/anlynes/archive/tags/.NET/default.aspx">.NET</category></item></channel></rss>