3

I need to write a very small application which writes some system data to a file and then exits. I could do this in a console application but I have no need or desire for a console window to appear during this process.

I would normally use a Windows Forms application with no forms, execute the code in the Main method and then allow the application to exit, however, this time I couldn't help but wonder if this is the best way to do it and whether you could do it with a WPF application instead, what the differences are and whether or not once you've remove any forms/windows and unnecessary reference, it matters or not.

4

2 回答 2

8

WPF 和 WinForms 是显示 UI 的两个不同库。

如果您从不显示 UI,那么您就没有使用它们中的任何一个。
您应该从 WinForms 项目开始(WPF 项目设置了您不想要的额外项目元数据),然后删除对System.Windows.Forms.dll.

或者,从控制台项目开始,然后将输出类型更改为 Windows 应用程序。

于 2013-10-10T19:07:58.640 回答
0

没有窗口或控制台应用程序且类型更改为 Windows 应用程序的 Windows 窗体将为您提供相同的结果,这是一个具有Main()方法的简单应用程序和现在的窗口。

WCF 仅在您确实想要显示某些内容时才有意义,因为您不会在您的案例中使用它的任何功能。

于 2013-10-10T19:10:28.220 回答