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 →
Month: April 2013
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 →