在运行时确定项目类型 [英] determine project type at runtime

查看:103
本文介绍了在运行时确定项目类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,

正在运行的程序如何确定自己的类型?

我正在开发一种内部软件,该软件基本上是一个控制台应用程序.它的用例是从另一个软件系统中调用,执行某些操作并返回一个返回值.

它会将一些内容输出到控制台,这有助于跟踪错误行为.但是,由于它经常被调用,因此控制台窗口不断弹出并迅速消失.用户抱怨屏幕闪烁.

将项目输出类型设置为"Windows窗体"可以消除该问题(不创建任何窗口),但也可以防止快速浏览帮助屏幕,该帮助屏幕像其他所有内容一样打印在控制台上.

我现在想将帮助屏幕的输出分支到控制台模式下的控制台,或窗体形式下的窗口.


知道我从哪里可以得到这些信息吗?

Hi experts,

how can a running program determine its own type?

I''m working on an in-house software that is basically a console application. Its use case is to be called from within another software system, do something and return a return value.

It''s outputting some stuff to the console, which helps tracking down erronuous behaviour. But since it''s called that often, the console window constantly popps into view and quickly vanishes. Users complain about the flickering on their screens.

Setting the project output type to "Windows Forms" eradicates that problem (no window is created), but also prevents from a quick look at the help screen, which is printed to the console like everything else.

I now would like to branch the help screen output to console in Console mode, or to a window in Forms mode.


Any idea where I could get that information from?

推荐答案

不好,但似乎可以工作:

我尝试读取Console.BufferHeight,如果抛出异常,则没有控制台,我使用Form进行输出.
Not nice, but seems to work:

I try to read Console.BufferHeight and if that throws an exception, then there is no console and I use a Form for output.


使用System.Diagnostics名称空间中的Debug或Trace代替安慰.然后,如果需要,只需启动 DbgView [ http://nlog-project.org/ [
Use the Debug or Trace from System.Diagnostics namespace instead of Console. Than, if you need, just start DbgView[^] to view the output.
Or simply use logging to file. This one is really good, and easy to use: http://nlog-project.org/[^]


如果您像Zoltan所说的那样进行记录,则可以通过读取日志文件的内容,可以轻松地在Windows窗体中显示日志.
If you are logging like mentioned by Zoltan, then you can easily show the log in windows form by reading the contents of log file.


这篇关于在运行时确定项目类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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