How to start a new instance of a second project in a new process

I want to show a window (WPF), which is defined in a separate class library project as a new separate process. Is there any way to do this?

I need to run the second instance of the project in a new process, because it remains occupied by memory when I start it as follows:

secondProject.WPFWindow win = new secondProject.WPFWindow();
win.Show();

I have one solution with multiple projects.

  • The StartUp project is a WPF application, output type: Windows application (exe file).
  • All other projects are a WFP application, output type: class library (dll file).

Now I run the “applications” (other projects in this solution built as dll) with this code:

secondProject.WPFWindow win = new secondProject.WPFWindow();
win.Show();

... Process.Start(), , exe agrument, ( ) DLL.

+5
2

.exe, , "" . .exe , -. , .exe Application:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        //See if exactly one command line argument was passed
        if (e.Args.Length == 1)
        {
            //See if the argument is one of our 'known' values
            switch (e.Args[0])
            {
                case "launchApp2":
                    secondProject.WPFWindow win2 = new secondProject.WPFWindow();
                    win2.Show();
                    break;
                case "launchApp3":
                    thirdProject.OtherWPFWindow win3 = new thirdProject.OtherWPFWindow();
                    win3.Show();
                    break;
            }
        }

        //Probably want to call the base class always?
        base.OnStartup(e);
    }
}

, - , :

public void LaunchApp2()
{
    //Start a new process that is ourself and pass a command line parameter to tell
    //  that new instance to launch App2
    Process.Start(Assembly.GetEntryAssembly().Location, "launchApp2");
}
+3

, - (EXE), - (DLL). , DLL (, ), EXE.

- DLL. EXE .... , . DLL. "".

EXE WPFWindow .

using secondProject;

, WPFWindow. , CTRL + Period.

, , DLL #. , , , , .

Edit:

. , XY Problem. , , , , ( , DLL) .

, , ( , WPFWindow) , DLL. DLL , - , .

EXE, WPFWindow, , Process. , , . : " , ?" " ?"

0

All Articles