Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Console.ForegroundColor per thread getting jumbled.

1 view
Skip to first unread message

Aju

unread,
May 10, 2008, 5:22:11 PM5/10/08
to
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?

Marc Gravell

unread,
May 10, 2008, 5:34:29 PM5/10/08
to
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

0 new messages