Launching application from another application
-
Hello, I have the following:
private void button_Click(object sender, EventArgs e) { this.demoThread = new Thread (new ThreadStart (this.ThreadProcSafe)); this.demoThread.Start(); } private void ThreadProcSafe () { MyReference.Form2 form2 = new Form2(); Application.Run(form2); }
I was just wondering if that's the proper way to do it? It must be a separate thread, but I just don't know if doing it the way I am doing it is good programming practice. Is there information regarding launching applications on a separate threads. Sort of showing top-level windows in it's own process thread. Thank you. -
Hello, I have the following:
private void button_Click(object sender, EventArgs e) { this.demoThread = new Thread (new ThreadStart (this.ThreadProcSafe)); this.demoThread.Start(); } private void ThreadProcSafe () { MyReference.Form2 form2 = new Form2(); Application.Run(form2); }
I was just wondering if that's the proper way to do it? It must be a separate thread, but I just don't know if doing it the way I am doing it is good programming practice. Is there information regarding launching applications on a separate threads. Sort of showing top-level windows in it's own process thread. Thank you. -
You want a new process, not a new thread.
System.Diagnostics.Process.Start(@"C:\MyApp.exe");
I load the other reference in the form of .dll. So how would I call that as another process? Other thing, my main window, that is launches the other processes, will show all the windows open in the window menu, and the only way to interact with the other windows is by using the worker threads. Thank you.
-
I load the other reference in the form of .dll. So how would I call that as another process? Other thing, my main window, that is launches the other processes, will show all the windows open in the window menu, and the only way to interact with the other windows is by using the worker threads. Thank you.
Read up on .Net app domains. What are you trying to do? Do you have to have a separate application or process running? Ok, only having one running app makes life easier so that you can use object references and all that. The app is already running, just show some forms without using threads. The UI is the UI. It should be thin. You don't have to model the UI after the physical implementation details (threads). Use the minimal amount of threads to do some work so that the UI isn't hung up waiting for a calcuation to finish (the UI remains snappy). When the thread is done, update the form UI to present it to the user. A form should not have much code in it, it is just the presentation to the user. Lookup BeginInvoke() on CP and google. If you really want to have some fun, you could use .Net Remoting to talk between apps. This way you can have independent apps up and they can talk to each other. Usually this is done when you have the exes running on separate machines. Jim
-
Read up on .Net app domains. What are you trying to do? Do you have to have a separate application or process running? Ok, only having one running app makes life easier so that you can use object references and all that. The app is already running, just show some forms without using threads. The UI is the UI. It should be thin. You don't have to model the UI after the physical implementation details (threads). Use the minimal amount of threads to do some work so that the UI isn't hung up waiting for a calcuation to finish (the UI remains snappy). When the thread is done, update the form UI to present it to the user. A form should not have much code in it, it is just the presentation to the user. Lookup BeginInvoke() on CP and google. If you really want to have some fun, you could use .Net Remoting to talk between apps. This way you can have independent apps up and they can talk to each other. Usually this is done when you have the exes running on separate machines. Jim
Thank you for your reply. I decided to use BeginInvoke, insted of creating a new Thread. What I am trying to do, is to have a main window application, which basically will have a list of applications to run. These apps are coded in C# as well, so I have to add them as references to the main window application. If the user launches one of these apps, I needed to be independent, because if that app displays a dialog box, it should only lock the access to the parent of that dialog box (built in), but not the access to the main window application, or other apps that might of being launch from the main window application. I hope that creates a picture for you. Thank you again
-
Thank you for your reply. I decided to use BeginInvoke, insted of creating a new Thread. What I am trying to do, is to have a main window application, which basically will have a list of applications to run. These apps are coded in C# as well, so I have to add them as references to the main window application. If the user launches one of these apps, I needed to be independent, because if that app displays a dialog box, it should only lock the access to the parent of that dialog box (built in), but not the access to the main window application, or other apps that might of being launch from the main window application. I hope that creates a picture for you. Thank you again
If you are going to launch exe's, then Process.Start (as previously mentioned) is what you want to call. Personally, I would not be launching exe's, but rather referencing the assemblies and creating an object which does what the Main entry point does for each "app." This way you can setup communication (if you want to down the road) since everything is running under the same app domain. If there is a modal dialog, then well, shouldn't the user be held hostage in order to reconcile the OK/Cancel dialog :) Jim