Month: April 2013

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 →

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 →