Monthly Archives: February 2006

Update UI the easy way using anonymous delegates.

We all know you can’t update the UI from another thread. The standard approach is to create a delegate for each UI update method and call that with BeginInvoke. That works, but can get messy when creating a bunch of … Continue reading

Posted in C# | 24 Comments

Parameterized Thread Start – The easy way.

Here is my method to easily call a parameterized method on a new thread or the thread pool.  using System;using System.Threading;using System.Collections.Generic;using System.Collections; namespace WJS.Threading{    /// <summary>    /// Generic parameterized delegate.    /// </summary>    /// <typeparam name="T">Type of method parameter.</typeparam>    /// <param … Continue reading

Posted in C# | 12 Comments

Fast and Fair ReaderWriter lock.

using System;using System.Collections.Generic;using System.Text;using System.Threading; namespace WJS.Threading{    /// <summary>    /// Fast and fair ReaderWriter lock.    /// </summary>    public class RW    {        private int nr = 0;        private int nw = 0;        private object writerLock = new object();        private object readerLock … Continue reading

Posted in C# | 3 Comments

Double-Checked Again. The way to do it.

public sealed class Singleton{    private static Singleton value;    private static object syncRoot = new Object();    private Singleton() { }     public static Singleton Value    {        get        {            if (Singleton.value == null)            {                lock (syncRoot)                {                    if (Singleton.value == null)                    {                        … Continue reading

Posted in C# | 11 Comments