Strange behaviour of Console.ReadKey() with multithreading

前端 未结 3 546
孤街浪徒
孤街浪徒 2020-11-27 22:41

I\'m getting a weird problem when using Console.ReadKey() in a multithreaded program.

My question is: Why is this happening? Is it a bug, or is it becau

3条回答
  •  佛祖请我去吃肉
    2020-11-27 23:12

    This is probably occurring BECAUSE it is multi-threaded. Your main thread is moving on and exiting before your async task has a chance to report back. When the main thread exits, all child threads are killed.

    What if you place a waiting before the ReadKey? does it output it correctly?

提交回复
热议问题