简体   繁体   English

如何在Visual Studio的同一项目中制作多个程序文件

[英]How to Make Multiple Program Files within Same Project in Visual Studio

I am making a simple program that: 我正在编写一个简单的程序,该程序:

  1. Automatically Runs on Startup (Invisibly) 在启动时自动运行(不可见)
  2. Finishes task within 5-10 seconds (Invisibly) 在5-10秒内完成任务(无形)
  3. Exits 退出

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: 有两个答案:

  1. 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 )运行该程序。

  2. 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.

相关问题 如何通过visual studio安装项目降级程序? - How to downgrade program by visual studio setup project? 同一个 window 中的多个 Visual Studio 文件 - Multiple Visual Studio files in the same window 创建一个Visual Studio项目并通过python程序向其中添加文件 - create a visual studio project and add files to it from a python program Visual Studio - Intellisense 无法识别同一解决方案中另一个项目中的命名空间 - Visual Studio - Intellisense not recognizing namespace in another project within same solution 如何在Visual Studio 2010中的项目文件夹中访问bin / debug中的文件? - How to access the files in bin/debug within the project folder in Visual studio 2010? 如何将xbf文件添加到visual studio项目中 - How to add xbf files to visual studio project 如何使用 c# 在 Visual Studio 2017 中为 1 个 selenium 项目创建 .exe 文件,其中包含多个类 - how to create .exe file in visual studio 2017 for 1 project of selenium using c# having multiple class within it 如何将单声道复制数据文件制作成子目录,就像Visual Studio一样 - How to make mono copy data files into subdirectory the same way visual studio does Visual Studio 2017 调试同一项目的多个实例 - Visual Studio 2017 Debug Multiple Instances of the Same Project 在Visual Studio中为C#项目管理多个配置文件 - Managing multiple configuration files in Visual Studio for a C# project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM