Is there a way to execute another program, such as notepad, as a thread so it shares the same memory space as my program? So if my program ends, so will notepad and so that notepad won't show up in task manager, just my program?
No, certainly not for a non-managed app like notepad.
For a managed app, however, you can load the assembly using the utilities in System.Reflection
and begin execution of the Main()
method (or, rather entrypoint).
However, there are a few features in the System.Process
class that can help you emulate what you are looking to do.
No. This would be a very bad idea, in any case, as it would potentially cause all sorts of nasty things to occur. The other program would have no way of knowing what it should initialize and what was already initialized by the hosting program, etc.
You can, however, force notepad to close with your program. Just call Process.CloseMainWindow (nice) or Process.Kill (force it to die) on the process you create when your application shuts down.
No, this is not possible (barring you trying to do some odd, virtualization style environment within a single process.)
To ensure that notepad dies with your app, create a job object, assign your app to it before launching notepad. When your program closes, the job object will be destroyed and all child processes in the job object will also be closed.
Theoretically, you could do the same job the OS loader does - load the executable, find the main entry point and call into it from your thread.
Note that you most probably will run in all sorts of app-compat problems, as the code in that executable does not expect it to be executed in this way.