Console.Write在.NET GUI应用程序 [英] Console.Write in .NET GUI Application

查看:149
本文介绍了Console.Write在.NET GUI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个C#.NET GUI应用程序。我还需要在后台的一些任务控制台。基本上,我使用的是第三人利益党库一些处理(花费大量的时间),这将它的中间结果的安慰。该处理是一个计算时间服用任务。所以,我分配这个任务给的BackgroundWorker。我的意思是后台工作调用这些库函数。但问题是,有没有办法,我展示计算的用户​​状态,因为我没有图书馆的来源。我希望控制台将显示。但令人惊讶的 Console.WriteLine 似乎并没有工作。我的意思是,没有表现出任何控制台窗口。怎么会呢?

In a C# .NET GUI Application. I also need the console in the background for some tasks. Basically, I'm using a Thrid Party library for some processing (takes lot of time) which writes its intermediate results to console. This processing is a computationally time taking task. So, I'm assigning this task to backgroundworker. I mean background worker calls these library functions. But problem is there is no way for me to show the user status of computation, because I don't have source of the library. I was hoping Console will be shown. But surprisingly Console.WriteLine doesn't seem to work. I mean, there isn't any console window shown. How come?

编辑:

我尝试设置应用程序类型=控制台。但似乎是一个问题。只是,主线程可以访问控制台。只有 Console.WriteLine S由主(应用程序)的线程中执行显示在控制台。 Console.WriteLine ■通过图形用户界面的其他(BackgroundWorker的)的线程中执行,输出将不会显示。我只需要为背景的工人控制台。我的意思是,当后台工作启动后,启动控制台和放大器;它结束时,控制台将被关闭。

I tried setting application type = console. But there seems to be a problem. Only, main thread is able to access the console. Only Console.WriteLines executed by main (Application) thread are displayed on console. Console.WriteLines executed by other (BackgroundWorker)threads of the GUI, the output is not shown. I need console only for Background workers. I mean, When background worker starts, console starts & when it ends console will be off.

推荐答案

创建你自己的控制台窗口,并使用 Console.SetOut(myTextWriter); 的方法来读什么写入控制台。

Create your own console window and use the Console.SetOut(myTextWriter); method to read anything written to the console.

这篇关于Console.Write在.NET GUI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆