-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PromptPlus output becomes messy from inside Parallel.ForEach or Parallel.Invoke functions #121
Comments
Hello ivideon, In other words, console operations do not work well with multi-threads unless the application itself manages the result and organizes the data before sending it to the console. Try this and see the result (it will be confusing too)
|
Looks like this can be improved with the following: internal static class Program
{
internal static object ConsoleWriterLock = new object();
static void Main(string[] args)
{
Console.Clear();
Console.WriteLine("write 100 line Without Parallel:");
for (int i = 0; i < 100; i++)
{
Console.Write("test Console.Write ");
Console.WriteLine($"value is {i} ");
}
Console.WriteLine("Press Any Key");
Console.ReadKey(false);
Console.Clear();
Console.WriteLine("write 100 line From inside Parallel.for:");
Parallel.For(1, 100, (i) =>
{
lock (ConsoleWriterLock)
{
Console.Write("test Console.Write ");
Console.WriteLine($"value is {i} ");
}
});
}
} Using Some kind of |
Pressed the wrong button... |
I'll also note that this issue doesn't occur if you do |
Tested with simple WriteLine.
From inside Parallel:
Without Parallel:
The text was updated successfully, but these errors were encountered: