SQL Server 2008 R2 SP1 Express Edition Download

15 02 2012

Here’s the link to the most recent version of SQL Server Express Edition (at 2012-02-16, the time of this writing):

SQL Server 2008 R2 SP1 Express Edition (10.50.2500.0) Download

Download the file SQLEXPRWT_x64_ENU.exe (329.9 MB) for 64-bit editions of Windows. WT stands for with tools.





WPF Application Shutdown on Windows 7 x64

3 02 2012

In WPF applications, the Application.Exit event is not (reliably) called – at least on Windows 7 x64 – when the user logs off from or shuts down or restarts the Windows machine. I found that my Application_Exit handler which performs important cleanup was not called.

I tried to remedy this first by hooking into the SystemEvents.SessionEnding event and calling Application.Shutdown from there. After doing this, I found that my Application_Exit handler was called, but then the process seemed to be killed in the middle of the shutdown processing (log output stopped suddenly).

Then I removed the SystemEvents.SessionEnding event handler again and tried to override the Application.OnSessionEnding virtual method. This resulted in the same behavior. The Application_Exit handler was sometimes called, sometimes not, but when it was called, the process died during shutdown processing.

I finally solved this by overwriting the Application.OnSessionEnding method, calling the base class implementation first, then setting SessionEndingCancelEventArgs.Cancel=true to avoid my process being killed by the OS, and finally explicitly calling Application.Shutdown to initiate the shutdown process. The end result is a clean application shutdown while Windows shows the „Application not responding“ screen for several seconds while my application shuts down.

Here’s the code:

public partial class App : Application
{
  protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
  {
    base.OnSessionEnding(e);

    // Cancel application shutdown to prevent Windows 7 killing
    // the process
    e.Cancel = true;

    // Terminate myself
    Shutdown();
  }
}