lock (o)
{
Console.ForegroundColor =
(ConsoleColor)Enum.Parse(typeof(ConsoleColor),
Attributes["ConsoleColor"]);
Console.Write(message);
Console.ResetColor();
}

I hoped each thread would get it's own color based on an external
parameter that's set at load time. However, ocassionlly outputs means
to be in green are coming out in red and so on.

Any ideas?

Re: Console.ForegroundColor per thread getting jumbled. by Marc

Marc
Sat May 10 16:34:29 CDT 2008

Well, I was going to say "add some locking"... so: what is "o"
here...? not everything is suitable for locking... and it must be the
same reference over all threads - the following would suffice:

public static class SharedLock {
public static readonly object Lock = new object();
}

then lock(SharedLock.Lock) {...}

Marc