[英]How to Make Multiple Program Files within Same Project in Visual Studio
I am making a simple program that: 我正在编写一个简单的程序,该程序:
I am a beginner and have one challenge here. 我是一个初学者,在这里面临一个挑战。 There are two programs.
有两个程序。 One which user can open to change settings (Windows Forms) and another that runs on startup, finishes task & exit.
一个用户可以打开以更改设置(Windows窗体),另一个可以在启动时运行,完成任务并退出。 How can I make two programs in a single project?
如何在一个项目中制作两个程序?
Also, where to save configuration so that both the programs can read/write it? 另外,在哪里保存配置以便两个程序都可以读取/写入配置?
Thanks for help in advance. 预先感谢您的帮助。
Update: The program is basically to clean the desktop on startup. 更新:该程序基本上是在启动时清理桌面。 Please check attached design of my software as well for better idea.
请检查我的软件的附件设计,以获取更好的主意。
There are two answers: 有两个答案:
You can make a program that reads the arguments in the Main
method to decide in which mode it should run. 您可以使程序读取
Main
方法中的参数,以决定应以哪种模式运行。 If run without arguments (such as when double clicked), it presents the user interface, and if run with some specific argument, like say /run
, it does not present the user interface and instead performs the task you want. 如果运行时没有参数(例如双击),它将显示用户界面,如果运行某些特定的参数(例如
/run
,它将不显示用户界面,而是执行所需的任务。 You don't specify how you get the task to happen at startup, but it will have to run this program with that argument ( /run
). 您无需指定如何在启动时执行任务,但必须使用该参数(
/run
)运行该程序。
The easier way to do this is to just make a new project for the program performing the task - that also lets you start and debug the task directly in Visual Studio. 执行此操作的更简单方法是为执行任务的程序创建一个新项目-这也使您可以直接在Visual Studio中启动和调试任务。
If you're making a conventional Windows application, you're free to save the settings wherever you'd like. 如果您使用的是常规Windows应用程序,则可以随意将设置保存在任何位置。 Saving them under a subfolder of the AppData folder in the user's home folder/"profile" is the recommended way.
建议将它们保存在用户主文件夹/“配置文件”中AppData文件夹的子文件夹下。 You can use
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
to get the path to the AppData folder and then make your own folder and files within it. 您可以使用
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
来获取AppData文件夹的路径,然后在其中创建自己的文件夹和文件。
You can also use the registry . 您也可以使用注册表 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.