Please note that as of Release 2.3 of SimpleInjector the features discussed in this and related articles are available out of the box with the new registration method RegisterAllOpenGeneric I like SimpleInjector, it’s great and so is the support. The guy behind SimpleInjector is a top class craftsman. However I recently discovered that SimpleInjector does not return any open generic… Read more →
Author: Peter
Trigonometry and Games Programming
Part 1 Read more →
How to cancel Parallel.ForEach
static void Main(string[] args) { List<RandomWait> waiters = new List<RandomWait>(); for (int i = 0; i < 1000; i++) { waiters.Add(new RandomWait()); } int counter = 0; ParallelOptions options = new ParallelOptions(); CancellationTokenSource cancelToken = new CancellationTokenSource(); options.MaxDegreeOfParallelism = 15; options.CancellationToken = cancelToken.Token; Task.Factory.StartNew(() => { Parallel.ForEach(waiters, options, (waiter) => { counter++; Console.WriteLine(counter); waiter.Pause(); counter–; Console.WriteLine(counter); }); }); Console.ReadLine(); cancelToken.Cancel();… Read more →
Create a new EventLog source
step into the Visual Studio debugger (must be running as Admin), go to the immediate window and enter System.Diagnostics.EventLog.CreateEventSource(new System.Diagnostics.EventSourceCreationData(<name>, “System”)); Read more →
You’ve got to love extension methods
public static class Roundings { public static decimal To2Dp(this decimal amount) { return Math.Round(amount, 2); } public static decimal To5Dp(this decimal amount) { return Math.Round(amount, 5); } public static decimal To6Dp(this decimal amount) { return Math.Round(amount, 6); } } Read more →
Roll-your-own lazy loading
Thanks to @dot_NET_Junkie for pointing me to this article How *not* to inject services into entities Here’s my version: public interface IEntityLoader<T> where T : class { bool IsLoaded { get; } T Value { get; } } /// /// This class has been designed to enable Lazy Loading within an Entity /// without the need for the Entity to hold a… Read more →
Aspect Oriented Programming (AOP)
We have found many programming problems for which neither procedural nor object-oriented programming techniques are sufficient to clearly capture some of the important design decisions the program must implement. This forces the implementation of those design decisions to be scattered throughout the code, resulting in “tangled” code that is excessively difficult to develop and maintain. We present an analysis of why certain design… Read more →
SQL Server count all rows in all tables
SELECT sysobjects.Name , sysindexes.Rows FROM sysobjects INNER JOIN sysindexes ON sysobjects.id = sysindexes.id WHERE type = ‘U’ AND sysindexes.IndId < 2 ORDER BY sysobjects.Namecode Read more →
MethodImplOptions.AggressiveInlining
MethodImplOptions.AggressiveInlining Read more →
css switcher
css switcher Read more →