Integrating your Application’s Threading Model with the Asynchronous Programming Model

In version 2.0 of the .NET Framework, Microsoft introduced the System.Threading. SynchronizationContext class. Simply stated, a SynchronizationContext-derived object connects an application model to its threading model. The FCL defines several classes derived from SynchronizationContext, but usually you will not deal directly with these classes; in fact, many of them are not publicly exposed or documented.…

Using AppDomains to make Non-Threadsafe code Threadsafe

Recently, I was involved in a Wintellect consulting engagement where a customer had some class library code that was created years ago. The code in this class library was not designed to work well in a multithreaded environment. Specifically, this means that if two or more threads called into the class library code at the…

Building a component that works with different versions of a library

It’s common to want to build a .NET component that works with different versions of a particular library. It is also common for newer versions of the library to introduce new methods that your component might want to call. However, if you build your component against the oldest version of the library you support, then…

AsyncEnumerator Survey for Microsoft

If you have never used my AsyncEnumerator class (which is part of my free Power Threading library) to simplify writing code that performs asynchronous operations, then you can ignore the rest of this blog posting. I have been working with Microsoft in an attempt to add my AsyncEnumerator (or something like it) into a future…

Receiving notifications when garbage collections occur

While creating the 3rd Edition of my CLR via C# book (http://www.amazon.com/CLR-via-C-Third-Pro-Developer/dp/0735627045/ref=dp_ob_title_bk), I came up with a cool little class that will raise an event after a collection of Generation 0 or Generation 2 occurs. Here is the code for the class: public static class GCNotification {   private static Action<Int32> s_gcDone = null; // The…

What’s new in CLR via C#, 3rd Edition as compared to the 2nd Edition

Last week I submitted the reaming chapters for my new book. It is now being edited and should be available right around the time that Visual Studio 2010 launches (March 22, 2010). One place you can order it is here: http://www.amazon.com/CLR-via-C-Third-Pro-Developer/dp/0735627045 I know that many people will ask me what are the differences between the…

Using .NET 4.0 Tasks with the AsyncEnumerator

I’ve been doing a lot of work with the new Task class that ships with .NET 4.0 as I’ve been revising my CLR via C# book (due out in early 2010). Task are really good for performing asynchronous compute-bound work and while my AsyncEnumerator was really designed for performing I/O-bound work using the CLR’s APM,…

Devscovery 2009 Redmond follow-up

During my CLR/BCL/C# 4.0 talk, a few people asked me questions for which I didn’t have the answer. I have now researched these questions and have the answers.   Question #1: Are the new concurrent collection classes in .NET 4.0 serializable? Answer: Yes, ConcurrentStack, ConcurrentQueue, ConcurrentBag, and ConcurrentDictionary are all serializable. However, the BlockingCollection class…

CLR via C#, 3rd Edition

I have been asked by many people if I will be updating my CLR via C# book for .NET 4.0. Well, I’m happy to report that the answer is YES! I have already signed the contract with Microsoft Press and have been busy writing. The new edition keeps its focus on the CLR and the C#…