views:

50

answers:

1

Hi, I am newbie here. I have an existing application (C#/Win forms). I need to add functionality to the application such that is can launch another instance of its own and make some of the controls in the form disabled. It may be very easy to implement this using simple inheritance or may be some if else loop , but this application has to inform its dependent assemblies of the state. I am looking for the most elegant to do this. I am not keen on modifying the current files, just adding on to the existing functionality. Any suggestions will be of great help.

+1  A: 

You can start another instance like this:

        System.Diagnostics.Process.Start(
            System.Reflection.Assembly.GetEntryAssembly().Location,
            "disable");

You can test the command line argument with code like this in the form constructor:

    public Form1() {
        InitializeComponent();
        if (Environment.CommandLine.ToLower() == "disble") {
            button1.Enabled = false;
            // etc..
        }
    }

To debug this, you must use Project + Properties, Debug tab, untick "Enable the Visual Studio hosting process".

Hans Passant
Thanks. Reasonably close to my requirement. But is this the most elegant way?. Since the disabling of controls has to be done in lots of forms and referenced assemblies.?.
Well, make it a static property. I trust you can bang this in shape to your liking.
Hans Passant