简体   繁体   中英

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

  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.

If you're making a conventional Windows application, you're free to save the settings wherever you'd like. Saving them under a subfolder of the AppData folder in the user's home folder/"profile" is the recommended way. 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.

You can also use the registry .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM