Monthly Archives: December 2006

1 Comment

[Update 2007-10-18: Check out my blog post on two new Windows updates that solved this problem for me]

Just when I thought that I had tackled my hibernate problems in Windows Vista, I encounter serious problems with the sleep option.

When my computer goes to sleep it crashes and reboots. When my computer was idle this happened every hour, because the Balanced power plan puts the computer to sleep after one hour of inactivity. So I changed my power plan to High Performance so the computer never goes to sleep automatically ;(

Yesterday I reinstalled Windows Vista, mainly to rearrange my hard disks, but the problem remains. Albeit without a reboot after the crash.

There are many others that encounter crashes as well according to the post Windows Vista's Hideous Wakeup Support.

My hardware configuration is:

Dell Dimension 8300 with Pentium 4 3.0 GHz, 1 GB RAM, ATI Radeon 9800 PRO, Soundblaster Audigy 2 and Hauppauge WinTV PVR PCI II.

Windows Vista has a new reliability monitor that recorded the crash last night:

Does anyone else, with or without a similar hardware configuration, experience such problems?

I know that Microsoft does not support and recommends against installing XNA Game Studio Express on Windows Vista. But this free (as in $0) product, that was released today (*), is too cool to skip. Since I only have Windows Vista installed on my machine I had to give it a try anyway.

XNA is a .NET based framework for creating and running your own games on both Windows and the Xbox 360. Microsoft has created a special version of the .NET 2.0 CLR that runs on the Xbox 360. Check out this and this Channel 9 video for more information on XNA. The second part has a very cool demo with live debugging in Visual Studio of a racing game running on an Xbox 360.

In short Microsoft's goal is "Bringing Game Development to the Masses".

XNA Game Studio Express is an add-on for Visual C# Express 2005. Since I read in the readme that it should be able to install on Windows Vista, I went ahead after installing Visual C# Express 2005.

The XNA GSE setup did not succeed because Visual C# Express crashed while registering the project templates. Running with elevated privileges and turning off User Account Control did not help. Forcing an install with no rollback by using "msiexec /i xnagse_setup.msi DISABLEROLLBACK=1" did not help either. Visual C# Express crashed while creating an XNA project.

Then I found out on the XNA Game Studio Express forum that I should install the Beta of Service Pack 1 for Visual C# Express first. This is not necessary on Windows XP, but it is on Windows Vista.

I created an XNA game from the included "Spacewar Starter Kit". The splash screen comes up with music and all but when I move the mouse over it, the cursor disappears. Controlling the game with the keyboard works a little odd because it seems to be optimized for two Xbox 360 controllers. The game has cool stereo sounds. This is a screenshot:

(*) As I found out from Erno de Weerd's blog.

1 Comment

Frans Bouma posted his thoughts on the reasons for the relative absence of big open-source project in MS/.NET land when compared to Java, Linux, PHP, etc. world.


I had an somewhat related IM discussion with a colleague (who shall remain anonymous unless he permits me to out him or outs himself in the comments 😉 this morning. Over the weekend he sent me a piece of non-commercial software he had written to try out. To my amazement he sent me just the compiled version and had even gone through the trouble of running an obfuscator on it so I couldn't be decompiled to readable code.


For a question related to his application I referred him to the P/Invoke.net site to find P/Invoke signatures for Win32 API's. He did not find the DLL he was looking for, so I suggested that he go figure out the signatures himself and contribute them to the site since pinvoke.net is a wiki. He said that would be too much trouble and he said he wasn't that "socialistic".


Is this a typical mindset for a .NET developer?


BTW: To his defense, my colleague did suggest that I post the code of my WCF ServiceProxyHelper on my blog 😉


I appreciate the power of open source and made a small contribution of my own based on a piece of open source from Hisham Baz. Judging by the e-mails I get about the RollingFileTraceListener, people find it useful. It has been downloaded 1900+ times from gotdotnet and I get about one support request a week. I did not even give a thought to the possibility of releasing only a binary version and obfuscating that.


How do you feel about contributing to the greater .NET community? Either during your spare-time or during working hours.


Should commercial software companies make more open-source contributions for the .NET world?

1 Comment

When you create a Windows Communication Foundation (WCF) service proxy class for a service by using svcutil.exe, it creates a proxy that derives from System.ServiceModel.ClientBase<TChannel>. This class implements IDisposable so you think you can use your proxy safely in a C# using statement and get guaranteed clean-up in the face of exceptions.

However, the System.ServiceModel.ClientBase<TChannel> class can throw exceptions from its Dispose method, because it calls its Close method. This can happen when it is in a faulted state. In that case you have to call Abort for clean-up. Most times you are not interested in knowing whether the Dispose fails or not and you just want to have guaranteed clean up of any resources held by the proxy.

Check out this discussion on the WCF forum for why Microsoft implemented the dispose in this way.

To prevent you from writing a lot of code to accomplish this clean-up, I have written a generic ServiceProxyHelper class that does it for you. You can download it here or view the code below. It only swallows expected exceptions in its Dispose method but it always cleans up by calling Abort.

The idea is that you derive a class from my ServiceProxyHelper<TProxy, TChannel> class. Insert your proxy class (that should derive from ClientBase<TChannel>) name for TProxy, and the service interface name for TChannel. The helper class wraps the proxy and doesn't directly expose its methods. From your derived class you can use the protected Proxy property to get access to the service proxy. You should add methods to your derived class that delegate to the proxy.

For our project we added convenience method to the derived helper that create request messages and unpack response messages. So our helper methods have a different signature than the methods on the proxy class itself.

This code is provided "AS-IS" without any warranties. You can change it to fit your needs.

 
using System;
using System.Collections.Generic;
using System.ServiceModel;

namespace LogicaCMG.ServiceAccess
{
    /// <summary>
    /// Generic helper class for a WCF service proxy.
    /// </summary>
    /// <typeparam name="TProxy">The type of WCF service proxy to wrap.</typeparam>
    /// <typeparam name="TChannel">The type of WCF service interface to wrap.</typeparam>
    public class ServiceProxyHelper<TProxy, TChannel>: IDisposable
        where TProxy : ClientBase<TChannel>, new()
        where TChannel : class
    {
        /// <summary>
        /// Private instance of the WCF service proxy.
        /// </summary>
        private TProxy _proxy;

        /// <summary>
        /// Gets the WCF service proxy wrapped by this instance.
        /// </summary>
        protected TProxy Proxy
        {
            get
            {
                if (_proxy != null)
                {
                        return _proxy;
                }
                else
                {
                        throw new ObjectDisposedException("ServiceProxyHelper");
                }
            }
        }

        /// <summary>
        /// Constructs an instance.
        /// </summary>
        protected ServiceProxyHelper()
        {
            _proxy = new TProxy();
        }

        /// <summary>
        /// Disposes of this instance.
        /// </summary>
        public void Dispose()
        {
            try
            {
                if (_proxy != null)
                {
                    if (_proxy.State != CommunicationState.Faulted)
                    {
                        _proxy.Close();
                    }
                    else
                    {
                        _proxy.Abort();
                    }
                }
            }
            catch (CommunicationException)
            {
                _proxy.Abort();
            }
            catch (TimeoutException)
            {
                _proxy.Abort();
            }
            catch (Exception)
            {
                _proxy.Abort();
                throw;
            }
            finally
            {
                _proxy = null;
            }
        }
    }
}

1 Comment

None other than Jim Allchin, the soon to retire Co-President of the Platform and Services Division at Microsoft, explains the new power management on the Windows Vista Team Blog.

He explains the rationale behind the Sleep and the new Hybrid sleep options.

This had been a mystery for me when I couldn't find the Hibernate option in Windows Vista. Eventually I found the answer in Windows Help and Support. The separate Hibernate option in the shutdown menu is missing by design when Hybrid sleep is enabled. Windows Help explains the difference between Sleep and Hybrid sleep. Hybrid sleep is a combination of Sleep and Hibernate: when your computer goes into hybrid sleep the contents of the RAM is dumped to disk but the RAM remains powered, so your computer is quickly available for use when you return. When you cut off the power to the computer or it looses power, everything is safely on disk and hybrid sleep is indistinguishable from hibernate.

The default Turn off option through the power button in the Start menu is Sleep for laptop computers. For desktop computers it is Hybrid sleep.

Check out Jim's post for the full story.