Syntax Error

Code samples and hints

WPF Model-View-ViewModel für Visual Studio 2008

The Model-View-ViewModel toolkit is intended to introduce the Model-View-ViewModel design pattern for building WPF applications to the broad WPF developer community.

The toolkit includes:

  • A Visual Studio 2008 template (Visual C# Express 2008 also supported)
  • Documentation
    • General introduction to M-V-VM
    • Walkthrough using the VS template
  • A complete WPF application demonstrating the M-V-VM pattern

Script to generate INSERT statements

This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It's very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes.


One of the most handy features introduced in SQL 2005 were the ranking functions; ROW_NUMBER(), RANK(), and DENSE_RANK(). For anyone who hasn’t been introduced to these syntactic gems, here’s a quick rundown:


Aufsteigende Zeilen-Nummer gemäss ORDER BY, optional beschränkt auf Subsets gegeben durch PARTITION BY.


Aufsteigende Zeilen-Wertigkeit/Rang (gleiche Zeileninhalte ergeben gleicher Rang) gemäss ORDER BY, optional beschränkt auf Subsets gegeben durch PARTITION BY. Es können Lücken entstehen, wenn mehrere Zeilen den gleichen Rang haben (Bsp. 1, 2, 2, 4, 5 <-- 3 wird ausgelassen, da 2 zwei Mal vorkommt).


Identisch zu RANK() mit der Ausnahme, dass keine Lücken in der Nummerierung entstehen (Bsp. 1, 2, 2, 3, 4 <-- inkl. 3)

SQL Server 2005 - Reindex der gesamten Datenbank

EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', 90)"
EXEC sp_updatestats

SQL SERVER 2005 uses ALTER INDEX syntax to reindex database. SQL SERVER 2005 supports DBREINDEX but it will be deprecated in future versions.

PanicButton - c# Control Class

This article is based on the following two blogs:

I created a c# class to control the PanicButton device.

If started, a BackgroundWorker waits for input from the USB device.
To allow the main application work independent from the device state, every state change or button press are reported as Events.

UsbDevice.cs (6.23 kb)

The code expects the original TenxHID.dll in your project.


The USB class can be used similar to this example:

public partial class Form1 : Form
    readonly UsbDevice usb = new UsbDevice();

    public Form1()
        usb.ButtonPressed += ButtonPressed;
        // usb.DeviceConnected += DeviceConnected;
        // usb.DeviceDisconnected += DeviceDisconnected;
        // usb.ListeningEnded += ListeningEnded;
        // usb.ListeningStarted += ListeningStarted;
        // usb.ErrorReport += Error;

    private void ButtonPressed(object source, EventArgs args)

    private void button1_Click(object sender, EventArgs e)

    private void button2_Click(object sender, EventArgs e)

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        if (usb.IsListening)
            e.Cancel = true;

Custom Main Method in WPF Applications

To run a custom Main Method in a WPF Application you can do the following steps:

  • Set the Build Action of App.xaml to Page
  • Create a custom Application class
namespace WpfCustomMainMethod 
     using System.Threading; 
     using System.Windows; 

     public class Program : Application 
          static void Main() 
               var app = new Program(); 
               app.MainWindow = new AppWindow(); 

          public void InitializeComponent() 
               this.Startup += ProgramStartup; 

          void ProgramStartup(object sender, StartupEventArgs e) 
               var splash = new Splash {Topmost = true}; 
  • Change the Startup Object from the Project to your new Application class
  • Edit the Project File and add the following line of code right after "</ProjectTypeGuids>":
<DesignTime Condition="'$(SolutionPath)'!='' AND Exists('$(SolutionPath)')">true</DesignTime>
  • Change the existing lines of the ApplicationDefinition block to this:
<ApplicationDefinition Condition="'$(DesignTime)'=='true' AND 
'$(BuildingInsideVisualStudio)'!='true' AND
'$(BuildingInsideExpressionBlend)'!='true'" Include="App.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </ApplicationDefinition>

Demo Project: (11.54 kb)

This How-To is based on the following blogs:

ReSharper and GUI-Testing

If you try to run a test like the following from NUnit, you will find that it does not work.
You get an InvalidOperationException telling you that “The calling thread must be STA, because many UI components require this”.

System.InvalidOperationException: Beim aufrufenden Thread muss es sich um einen STA-Thread handeln, da dies für viele Komponenten der Benutzeroberfläche erforderlich ist.


Tired of querying in antiquated SQL?

Well, you don't have to!  LINQPad lets you interactively query SQL databases in a modern query language: LINQ.  Kiss goodbye to SQL Management Studio!

LINQPad supports everything in C# 3.0 and Framework 3.5:

  • LINQ to Objects
  • LINQ to SQL
  • Entity Framework
  • LINQ to XML

LINQPad is also a great way to learn LINQ: it comes preloaded with 200 examples from the book, C# 3.0 in a Nutshell.  There's no better way to experience the coolness of LINQ and functional programming.

And LINQPad is more than just a LINQ tool: it's a code snippet IDE that instantly executes any C#/VB expression, statement block or program – the ultimate in dynamic development. Put an end to those hundreds of Visual Studio Console projects cluttering your source folder!

Best of all, LINQPad standard edition is free and can run without installation (or with a low-impact setup). The executable is 3MB and is self-updating.

List & Label Log File

Enable Log File Debugging on app.config 

   <add key="ListLabel DebugLogFilePath" value="c:\combit.log"/>
   <add key="ListLabel EnableDebug" value="1"/>

Standard-Culture definieren

Der folgende Aufruf definiert die aktuelle System-Sprache als aktive Culture innerhalb der gesamten Applikation.

public partial class App : Application
    static App()
             typeof (FrameworkElement),
             new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name)));

Soll die Culture-Zuweisung nur für ein Window gelten, kann die vereinfachte Zuweisung verwendet werden:

<Window x:Class="Window1"
    Title="Window1" Height="300" Width="300"