Click here to Skip to main content
15,509,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application which contains two projects. In the application when I close the secondary project, I just want to close the secondary project and not the application. However, when the secondary project is run on as a standalone, when I close I want to use Application.Exit. Is there any way to determine if a project is running as a standalone or if it is part of another solution. Hope that makes sense

What I have tried:

Don't have a clue how to determine this.
Updated 15-Mar-21 7:47am
Richard MacCutchan 15-Mar-21 12:50pm    
"when I close the secondary project, I just want to close the secondary project and not the application."
If I understand the question the secondary is also an application. it is not clear how the two projects are connected.
Gary_Corbell 15-Mar-21 13:06pm    
Thanks for reply, Richard...OriginalGriff, below, gave me the answer I needed.
Richard MacCutchan 15-Mar-21 13:12pm    
Well, he is the expert on everything.

1 solution

Let's just summarise:
Your Solution has two Projects PA and PB, both of which are executable.
In the PB code, you want to know if the user started PA or PB so that a "close" request in PB can either close the app or just the forms etc. from PB.

There is no direct way to tell that. But ... you could read the Environment.CommandLine Property (System) | Microsoft Docs[^] which would tell you which EXE file was started.

However, generally speaking, you shouldn't use Application.Exit directly at all, just close the form and lets it's parents handle Form.Closed to close themselves as needed. When the main (first or startup) form closes, the application will close automatically.
Share this answer
Gary_Corbell 15-Mar-21 13:03pm    
Thanks OG......great advice and accepted. Appreciate your time.
OriginalGriff 15-Mar-21 13:16pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900