运行代码,一旦退出无形的应用程序:Windows窗体或WPF ...有什么关系? [英] Run code once and exit formless app: Windows Forms or WPF... does it matter?

查看:115
本文介绍了运行代码,一旦退出无形的应用程序:Windows窗体或WPF ...有什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写一个很小的应用程序,一些系统数据写入一个文件,然后退出。我能做到这一点在控制台应用程序,但我没有需要或愿望的控制台窗口在此过程中出现。

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.

我通常会使用一个Windows窗体应用程序没有形式,在Main方法执行的代码,然后允许然而,应用程序退出,这次我忍不住想知道这是做的最好的方式,以及是否可以用一个WPF应用程序做它,而不是什么的差异,以及是否一旦你删除任何形式/窗口和不必要的参考,它的问题还是不行。

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.

推荐答案

WPF和WinForms是显示用户界面两个不同的库。

WPF and WinForms are two different libraries that show UIs.

如果你从来没有显示用户界面,您不使用其中任何。结果
。您应该用WinForms项目启动(WPF项目设置你不想额外项目的元数据),然后删除引用 System.Windows.Forms.dll中

If you never show a UI, you aren't using either of them.
You should start with a WinForms project (WPF projects set extra project metadata that you don't want), then delete the reference to System.Windows.Forms.dll.

另外,启动一个控制台项目,然后更改输出类型的Windows应用程序。

Alternatively, start with a console project, then change the Output type to Windows Application.

这篇关于运行代码,一旦退出无形的应用程序:Windows窗体或WPF ...有什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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