c# Running my c# DLL from another App
I have a WinForms app which I have compiled to DLL.
I would like to u开发者_JAVA技巧se the dll to run start the app from another winforms app. So App A will have an option to run App B.
What is the best way to achieve this? Should I be using a DLL for this my win forms app or is EXE the better option?
Thanks!
When app B is completely independant of app A, you should use an EXE and start it with
System.Diagnostics.Process
(or so). Otherwise you could instantiate the main window class of app B in app A with new
to 'start' that app. In that case you can also use an EXE instead of a DLL, which can also be referenced as assembly.
I'd make the .dll into a .exe. If you have the source code for the .dll file, then you can modify the project output on the project properties page to output an executable binary. If you don't have the source code, then you can create a new project that builds to a .exe. The new project should reference and invoke the .dll file.
To launch the .exe from your C# application (assuming the .exe is in the same place as your main application .exe), call Process.Start as follows:
Process.Start("MyOtherApplication.exe", "arg0 arg1 arg2");
This will start the application as a completely separate windows process. So killing your first application will have no effect on the second one.
@Matthias suggested launching the other application using the new
operator. If you wanted the two applications to have the same lifetime, and perhaps share memory, then this may be appropriate.
精彩评论