C# Pass Arguments to the first instance of a program

Sometimes you don’t want the user to run more than one instance of a program. But if the user associates a filetype with your programm it shall open the filetype in this first instance. The code below uses interprocess communication to find out if there is already another instance. It further allows the first instance to register an eventhandler which can be called from a second instance in order pass its command line parameters to the first instance.

This is how to use the code:

This is the SingleInstanceEnforcer class

C# Pitfalls

Closures

If you have code like this:

The result will be that each button shows a Messagebox with c. Altough one would expect to see a MessageBox with a for the first button. The reason is that the foreach loop gets unrolled into a while loop which has it’s str variable declared outside of the loop. The statement in the loop does not catch the value of the variable but the variable itself. After the foreach loop the value of the variable str is c.

See Blog-Post for details

Oracle Index – Synchronize periodically

You can create an index which will be synchronized automatically everytime you commit:

or just periodically (p. x. every hour):

See Topic on StackOverflow

Oracle SQL Functions

WIDTH_BUCKET

This function lets you create histograms.

This query does first (inner select) assign a bucket to the companies. This will be a number between 0 and 11. 0 is any company which has a minus value (underflow bucket), 1 is a company having a value between 0 and 100, 2 between 101 and 200, … 11 are all companies that have a value of more than 1000 (overflow bucket). The outer select does then group all companies according to their value. At the end we get a result like 5 companies have a value between 0 and 100, 300 companies have a value betwwen 101 and 200 and so on.

See Oracle Documentation about WIDTH_BUCKET

Oracle log script errors in a table

Prepare a table to store the script error logs

Prepare a method to call if an error happens in a script:

Short example how to use it:

Oracle tnsnames configuration

Usually the file is located under:

You can add an entry like this:

If everything is ok you can try to test the connection

Issuing a ping

or login as user

or login as sysdba

Disable validation of Self-Signed Certificates

You can use the following code:

Be aware that this code does just accept every certificate and it is not only active for one request but for all requests. You should think before you use this code. But for development convenience or on a test system it might be ok to make your program easier to install and test.