In this post I will demonstrate how to verify if a given password meet the current Windows password policy. We will use the NetValidatePasswordPolicy API for that. Instead of using C# pinvoke approach, we will call the API through Managed C++ then call the managed C++ DLL with C#. This approach will be much more cleaner [...]
Archive for the ‘C# 3.0 Tips’ Category
Check if a password meet the current password policy
Posted in C# 2.0 Tips, C# 3.0 Tips on June 15, 2010 | 7 Comments »
Accessing 64 bit registry from a 32 bit process
Posted in C# 2.0 Tips, C# 3.0 Tips, C#4.0 Tips on May 10, 2010 | 4 Comments »
As you may know, Windows is virtualizing some parts of the registry under 64 bit. So if you try to open, for example, this key : “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90″, from a 32 bit C# application running on a 64 bit system, you will be redirected to : “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\90″ Why ? Because Windows uses [...]
Serialization & Deserialization of immutable objects
Posted in C# 2.0 Tips, C# 3.0 Tips, tagged Serialization on April 19, 2010 | Leave a Comment »
Introduction When developping our applications we can experience than some reference types have the same behavior than value types. As a matter of fact there is no more references to the copied object . It’s the case for System.String and System.Nullable<T> which are called immutable object because when affecting new value to these variables a [...]
How to execute code in another AppDomain that the current one
Posted in C# 2.0 Tips, C# 3.0 Tips, C#2.0 Exam 70-536, tagged C# on April 6, 2010 | Leave a Comment »
Introduction When an assembly has been loaded in an Application Domain, the embeded code can be executed. This code can be executed in the current Application Domain or in another one, we will see how to proceed by differents way. For all the following examples we will use a namespace MyNameSpace containing 2 classes : [...]
IoC Pattern
Posted in C# 2.0 Tips, C# 3.0 Tips, C#4.0 Tips on March 10, 2010 | 2 Comments »
Introduction: IoC (inversion of control) is a design pattern used to uncouple classes to avoid strong dependencies between them. As a matter of fact every system does not make assumptions about what other systems do or should do, so no side effect when replacing a system by another one. Let’s have a first example showing [...]
Understanding MultiCore CPUs Power by Runing Multiple Processes
Posted in C# 2.0 Tips, C# 3.0 Tips, Threading, tagged MultiCore on October 23, 2009 | Leave a Comment »
According to me, threading is the most interesting and exciting part of C#. Exploiting the power of multiple processors in order to build more faster and more responsive software is a great challenge. But to fully exploit this in your applications, you need to write multithreading code, which means learning some challenging new concepts. I’ll try as [...]
Avoid beep sound when you press Escape or Enter (OnKeyPress Event) on a focused control
Posted in C# 2.0 Tips, C# 3.0 Tips, tagged C# on October 21, 2009 | Leave a Comment »
Yesterday, i was facing a curious problem on my form. I have a DateTimePicker control , and when i choose manually the date and i press Enter or Escape, i have an annoying sound. You know, this sound that is heard when Windows displays an error message box. I have bypassed the problem by creating [...]
How to set the processor affinity programmatically
Posted in C# 2.0 Tips, C# 3.0 Tips, tagged Performing on October 20, 2009 | Leave a Comment »
If you have a multiple processors (or multi-core processor), you can use the Processor Affinity to direct a specific process to use a specified core. By this way, if your process always use the same core, the process will run more efficiently because of the cache re-use. You can set the Processor Affinity in the [...]
Generic delegate Func
Posted in C# 3.0 Tips, tagged Delegate on September 4, 2009 |
Here’s a new feature introduced in C#3.0 : Func Func is a new type used in all concerning delegate declarations. In this post, we will show you the different states in using delagates declaration between C#1.1, 2.0 and 3.5. The following examples show if a data is included in a given interval. In C#1.0 the code [...]