Nov 22

Recently, another software developer in the United Kingdom and myself started a new open source project on CodePlex called BlogEngine.NET Photo Gallery. This is a branch of the popular BlogEngine.NET project. We are integrating new media management features (such as a photo gallery) to this blogging website application. The project is progressing amazingly fast. At this rate, I expect we will have not only have support for a simple a Photo Gallery (my original goal), but also several custom extension like Watermarks and various types of Slide Presentations done by Christmas! We eventually hope to merge our changes and additions back into the official BlogEngine.NET source code tree in the near future.

Nov 19

The long awaited release of Visual Studio 2008 is now over. Earlier this morning I noticed that Microsoft updated the Visual Studio Express Edition web site with the final 2008 Express editions (rather than just beta 2). A few hours later, Scott Guthrie announced that they released golden master DVDs to manufacturing. If you are a MSDN subscriber, you can download VS 2008 from the MSDN subscription site immediately. Retail packages will take a few weeks to get out. Of course, the Express editions are free!

Nov 14

I recently installed these Phoenix Gold ATC-6 6 1/2" 200-Watt 2-Way In-Ceiling Speakers in the family room. They were very easy to install. To cut a perfect circle for the speaker to fit in, I used a cordless Ryboi 18 volt spiral saw with the circle cutter jig. For only $34.99 a pair including shipping, these inexpensive, quality speakers were a great buy at www.buy.com.

Tags:
Nov 14

Lately, I have written a lot of multithreaded code in C#. I use the ThreadPool class object to launch and manage many parallel threads - mostly for TCP communications with clients application. It automatically throttles the numbers of active threads by the number of processors. Unfortunately, the ThreadPool class was written before .NET 2 and therefore it does not take advantage of generics and you end up casting function methods and callback parameters back and forth. It can be a bit messy.

However, you can simply things with the following helper class:

static class ThreadPoolHelper
{
  public delegate void Function();

  public static void Execute(Function function)
  {
    ThreadPool.QueueUserWorkItem(new WaitCallback(Call), (object)function);
  }

  private static void Call(object o)
  {
    ((Function)o)();
  }
}

 

With this code, to create a thread in the pool, you simple use:

TheadPoolHelper.Execute(someFunction);

 

Where someFunction is the name of a function method which does not have any parameters. 

If you need to pass a parameter, here's the helper class for that too:

static class ThreadPoolHelperWithParam<T>
{
  public delegate void Function(T param);

  public static void Execute(Function function, T param)
  {
    ThreadPool.QueueUserWorkItem(new WaitCallback(Call), new KeyValuePair<object, T>((object)function, param));
  }

  private static void Call(object o)
  {
    KeyValuePair<object, T> lObject = (KeyValuePair<object, T>)o;

    ((Function)lObject.Key)(lObject.Value);
  }
}

 

Now you can also pass an object of any type, like this:

ThreadPoolHelperWithParam<someObjectType>.Execute(someMethod, someObject);

Where the someObjectType is the type of object you are passing, and someObject with actual object you wish to pass as a parameter. Simple!

 

Tags: