0

I have written a Winforms application that will function in two ways:

  1. If no command line arguments are supplied, the main form of the application will show, and the user can interact with the application.

  2. If a command line argument is supplied, the main form is not shown, and the application perfoms the operation defined by the command line argument and then shuts down.

I would also like to display the command line argument to the user in a MessageBox, if the application is run from the Visual Studio IDE and the command line arugment has been specified in the Properties\Debug page.

Welton v3.62
  • 2,210
  • 7
  • 29
  • 46

2 Answers2

3

You could always use System.Diagnostics.Debugger.IsAttached

Russell Troywest
  • 8,635
  • 3
  • 35
  • 40
2

If you need to determine the "parent process" of a given process, here is a link on SO: How to get parent process in .NET in managed way

That being said, what I would do instead is split your program in two: one class library (a DLL, that will contain all the real meat of what your program does) and one EXE that references this class library. This way you can create a 3rd project as a VS Addin that will also reference this class library, but will implicitely be aware that it's running from VS.

Community
  • 1
  • 1
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • My solution is already seperated into Presentation (WinForms .exe) , BLL and DAL (.dlls) layers. Using a VS Addin is an interesting idea. I will give that a try. Though my main interest is to avoid confusion if another developer needs to pick up the project and nothing appears to happen when the WinForms app is run from VS with command line args already assigned in properties. – Welton v3.62 Apr 24 '11 at 14:53