Lazy: “The function evaluation requires all threads to run”

I have a static class with some static properties. I initialized all of them in a static constructor, but then realized that it is wasteful and I should lazy-load each property when needed. So I switched to using the System.Lazy type to do all the dirty work, and told it to not to use any of its thread safety features since in my case execution was always single threaded.

I ended up with the following class:

public static class Queues
{
    private static readonly Lazy<Queue> g_Parser = new Lazy<Queue>(() => new Queue(Config.ParserQueueName), false);
    private static readonly Lazy<Queue> g_Distributor = new Lazy<Queue>(() => new Queue(Config.DistributorQueueName), false);
    private static readonly Lazy<Queue> g_ConsumerAdapter = new Lazy<Queue>(() => new Queue(Config.ConsumerAdaptorQueueName), false);

    public static Queue Parser { get { return g_Parser.Value; } }
    public static Queue Distributor { get { return g_Distributor.Value; } }
    public static Queue ConsumerAdapter { get { return g_ConsumerAdapter.Value; } }
}

When debugging, I noticed a message I've never seen:

The function evaluation requires all threads to run

enter image description here

Before using Lazy, the values were displayed directly. Now, I need to click on the round button with the threads icon to evaluate the lazy value. This happens only on my properties that are retrieving the .Value of Lazy. When expanding the debugger visualizer node of the actual Lazy object, the Value property simply displays null, without any message.

What does that message mean and why is it displayed in my case?

17
задан Allon Guralnek 7 August 2013 в 18:07
поделиться