Console app that opens a new window for each thread started by background worker

白昼怎懂夜的黑 提交于 2019-12-13 21:22:42

问题


I have a console application that starts multiple different threads. The main console app will poll a service and based on responses it will spawn one or more background threads using the BackgroundWorker class. At the moment each of these threads do a console.writeline to the sole default console window opened as it normally does for a console application. This makes it too confusing to follow the progress of any one thread.

I want to be able to spawn a separate window with each of them writing their own console.writeline() to their own windows. When done, the main console app window will close the spawned console window, and then start it up again when it needs to.

I have not been able to find anything useful on this online. Im probably not using the correct keywords in my search. Any help in this please?


回答1:


It is not possible to have a separate console window for each thread. There can be only one console per process. You may want to look at this thread thread having its own console




回答2:


As a follow up to Vladimir's comments there's a nice sample app here that demonstrates attaching and detaching from a console and changing the display colors and locations and has some c# libraries build around the Windows Console API.

http://www.mischel.com/diary/2006/08/19.htm



来源:https://stackoverflow.com/questions/19381696/console-app-that-opens-a-new-window-for-each-thread-started-by-background-worker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!