C# Multithreading

Execute code in the UI Thread

Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, () => {
                Mouse.OverrideCursor = Cursors.Wait;

Log4Net take the name of the actual class for the logger


Oracle SQL-Script output

First you need to activate it and call the script:

set serveroutput on format wrapped;
call SOME_SCRIPT(150);

In the script you can output something with that line:


After the script has been executed you can see the output for example in the Script Output tab of SQLDeveloper.


PInvokeStackImbalance Excpetion

If you get a PInvokeStackImbalance exception it could be:

  • One parameter has a wrong type (p. x. int changed to long)
  • The CallingConvention of the DllImport. Change it in the declaration:
    [DllImport("user32.dll", EntryPoint="SetWindowLongA", SetLastError=true)]
    		private static extern long SetWindowLong (IntPtr hwnd, int nIndex, long dwNewLong);

    for example to

C# Show Console in WPF App

Use the following snippet to declare the Win32 function

        [DllImport("kernel32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool AllocConsole();

and this one to show the console


Revisioncontrol with Git

The most fundamental difference between Git and other revision control systems like SVN or CVS is the way how you work with it. With Git you will usually clone a repository. This creates a directory on your desktop where all the data about all revisions is stored. This means that you are not depending on a server somewhere. You can easily just use git locally.


C# Performance/Memory Pitfalls

Some things you could look for in the code


Rename Pictures based on Exif information

exiv2 -r'%Y-%m-%d %H%M :basename:' rename $(ls)
Renames all pictures in a directory. For example the file DSCF1200.jpg will be called 2011-12-30 1210 DSCF1200.jpg.


Mount Windows File Shares

Mounts the folder photo on from the server into the directory mount on our local machine. It uses youruser and youpassword to authenticate

sudo mount -t cifs -o username=youruser,password=yourpassword // /mount/


Installation of Certificate into Trusted Root Certification Authorities store

If you visit a webpage with a self-signed certification you will usually see the following warning: There is a problem with this website's security certificate.

To avoid the messge you need to install the certificate into the Trusted Root Certification Authorities certificat store. This can be done very easily with executing the following command:

certmgr -add Certificate.cer -s -r localMachine root

The certmgr command line tool can be found in the Windows Driver Kit Version 7.1.0



Subscribe to uhlme.ch RSS