Syntax Error

Code samples and hints

How to keep the display on during audio/video playback

How to keep the display on during audio/video playback


// Create this variable at a global scope. Set it to null.
private DisplayRequest dispRequest = null;

public void StartVideoPlayback()
    if (dispRequest == null) 
        // Activate a display-required request. If successful, the screen is 
        // guaranteed not to turn off automatically due to user inactivity.
        dispRequest = new DisplayRequest();
        rootPage.NotifyUser("Display request activated",
        // Insert your own code here to start the video.

public void StopVideoPlayback()
    // Insert your own code here to stop the video.
    if (dispRequest != null)
        // Deactivate the display request and set the var to null.
        dispRequest = null;
        rootPage.NotifyUser("Display request released",


SharpSerializer - serializer for .NET Framework

SharpSerializer is an open source serializer for .NET Framework and .NET Compact Framework. It's purpose is simple and quick object serialization from A to B, without security considerations. SharpSerializer can a lot more than the built-in XMLSerializer and does it simpler. It can serialize to XML such types as a generic dictionary, multidimensional array, nested array/array of array, polymorphic/inherited objects.

Load from File

var ss = new Polenter.Serialization.SharpSerializer();
 var store = (MyDataType)ss.Deserialize(filePath);

Save to File

var ss = new Polenter.Serialization.SharpSerializer();
 ss.Serialize(filePath, objectToSerialize);


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;

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"/>


Sucht ein Objekt in einem Array

return Array.Exists(intValueArray, delegate(int singleArrayValue) { return (intVergleichValue == singleArrayValue); });


DataRow[] temp = myDataSet.MyTable.Select("ID = 1");
MyDataSet.MyTableRow[] mtRows = 
    Array.ConvertAll<DataRow, MyDataSet.MyTableRow>(temp, delegate(DataRow from) { return (MyDataSet.MyTableRow)from; });

Retrieving Identity or Autonumber Values into Datasets

You can set a column in a DataTable to be an auto-incrementing primary key in order to ensure a unique value for each row in the table. However, you may have multiple clients for your application, and each of those clients can be working with a separate instance of the DataTable. In this case, you might end up with duplicate values between the separate instances of the DataTable. Because all your clients are working with a single data source, you can resolve this conflict by letting the data source define the auto-incremented value. To accomplish this you use Identity fields in Microsoft SQL Server

Using the data source to populate an Identity or Autonumber column for a new row added to a DataSet creates a unique situation because the DataSet has no direct connection to the data source. As a result, the DataSet is unaware of any values generated automatically by the data source. However, with a data source that can create stored procedures with output parameters, such as Microsoft SQL Server, you can specify the automatically generated values, such as a new identity value, as an output parameter and use the DataAdapter to map that value back to the column in the DataSet.

Special Webservice Call

Code um einen Webservice manuell anzusprechen.

using System;
  using System.Net;
  using System.Web.Services.Protocols;

namespace ConsoleApplication1
    internal class Program
        private static void Main(string[] args)
            DlgExport_BezugInterfaceHttpService dlg = new DlgExport_BezugInterfaceHttpService();

            WebProxy webProxy = new WebProxy();
            dlg.Proxy = webProxy;

            string[] egids = new string[1];
            egids[0] = "15647";

            getGebaeudeAllByEgid b = new getGebaeudeAllByEgid();
            b.Egids = egids;

                getGebaeudeAllByEgidResponse response = dlg.getGebaeudeAllByEgid(b);
            catch (SoapException ex)
                throw  ex;

Excel-Export ohne Excel (auch für Web)

Microsoft Excel ist ein beliebtes Werkzeug, um mit Tabellen zu arbeiten. Deshalb wird es bei den Endanwendern hoch geschätzt, wenn eine Anwendung Daten im Excel-Format exportieren kann. Da viele Geschäftsanwendungen heute allerdings Webanwendungen sind, gibt es mit Excel ein Problem. Auf dem Webserver ist Excel nicht installiert. Selbst wenn, würde ein Excel-Export mit COM Fernsteuerung des Excel-Objektmodells niemals schnell und zuverlässig funktionieren. Was nun?

Seit Excel 2003 gibt es einen sehr einfachen Weg, Excel-Dokumente ganz ohne Excel zu erzeugen, und zwar mit XML. Das kann eine PHP- oder ASP.NET-Anwendung ohne Probleme. XML ist ja nur Text und kann theoretisch sogar mit einfacher Stringverkettung erzeugt werden.

Performance Counter

Performance Counter um z.B. den benötigten Arbeitsspeicher auszulesen.

PerformanceCounter ramCounter; 
ramCounter = new PerformanceCounter("Prozess", "Virtuelle Bytes (max.)"); 
ramCounter.InstanceName = Process.GetCurrentProcess().ProcessName; 
Debug.WriteLine(string.Format("max. Speicherbedarf: {0}", (ramCounter.NextValue() / 1024.0)));