I need help starting multiple and communicating between application domains [modified]
-
Hello, I am going to have a Windows Forms project start in a day or two that will need me to have an application that will be able to reset itself to its initial state if the database connection is lost. What I would like to do is to create the process so it contains 2 application domains - one (the child) where the bulk of the application will be running and another (the parent) which monitors the database connection and restarts the child appdomain if connectivity is lost. I also need the ability to send simple messages between the two appdomains. I don't expect anyone to write any code for me, I just have had trouble finding concrete examples of how to do all this online and I would like someone to confirm whether I've got the general idea right or not. That being said, is this how you would do it: 1) Create two windows forms projects; the child and the parent. Set the parent as the starting project. 2) In the child application have a method something like:
public class Form1 {
public static Form1() StartApplication() {
Form1 f = new Form1();
}
}- The parent runs in the default application domain. When the parent is started, Create a new domain using d=AppDomain.CreateDomain("new domain"), load the executable created by the child project into it using d.Load(filename), and then use .NET remoting (which I still need to read up on) to call Form1.StartApplication() 4) Communicate between the domains using a .NET Remoting Channel (what is the best option for communicating between 2 appdomains in the same process?) 5) To restart the other domain call AppDomain.Unload(d), then create a new domain and load assembly as before. I need to use certain proprietary controls in the application so I would prefer to keep with .NET 1.1 - if that poses any particular problems however I suppose it shouldn't be a tremendous amount of trouble to upgrade. Once the project starts, I'm not going to have a lot of time to research and I don't have a Guru to go to so I put myself at your mercy. Am I missing anything here? Is this how you would do it? Is there any online tutorials you guys can recommend?
modified on Friday, May 9, 2008 9:53 AM
-
Hello, I am going to have a Windows Forms project start in a day or two that will need me to have an application that will be able to reset itself to its initial state if the database connection is lost. What I would like to do is to create the process so it contains 2 application domains - one (the child) where the bulk of the application will be running and another (the parent) which monitors the database connection and restarts the child appdomain if connectivity is lost. I also need the ability to send simple messages between the two appdomains. I don't expect anyone to write any code for me, I just have had trouble finding concrete examples of how to do all this online and I would like someone to confirm whether I've got the general idea right or not. That being said, is this how you would do it: 1) Create two windows forms projects; the child and the parent. Set the parent as the starting project. 2) In the child application have a method something like:
public class Form1 {
public static Form1() StartApplication() {
Form1 f = new Form1();
}
}- The parent runs in the default application domain. When the parent is started, Create a new domain using d=AppDomain.CreateDomain("new domain"), load the executable created by the child project into it using d.Load(filename), and then use .NET remoting (which I still need to read up on) to call Form1.StartApplication() 4) Communicate between the domains using a .NET Remoting Channel (what is the best option for communicating between 2 appdomains in the same process?) 5) To restart the other domain call AppDomain.Unload(d), then create a new domain and load assembly as before. I need to use certain proprietary controls in the application so I would prefer to keep with .NET 1.1 - if that poses any particular problems however I suppose it shouldn't be a tremendous amount of trouble to upgrade. Once the project starts, I'm not going to have a lot of time to research and I don't have a Guru to go to so I put myself at your mercy. Am I missing anything here? Is this how you would do it? Is there any online tutorials you guys can recommend?
modified on Friday, May 9, 2008 9:53 AM
Why do you think you need two domains? You can have a single app with multiple threads (at least 2 in this case). One thread for the windows form to run in and another which will check the connection periodically. If connection is lost then re-initialize the application. This will make everything a lot simpler as you do not need to bother with remoting. Let me know if I am missing something.
-
Why do you think you need two domains? You can have a single app with multiple threads (at least 2 in this case). One thread for the windows form to run in and another which will check the connection periodically. If connection is lost then re-initialize the application. This will make everything a lot simpler as you do not need to bother with remoting. Let me know if I am missing something.
Well yes, there's a couple other issues. Essentially, in order to do this I would have to create another program which would have as its sole duty restarting the application, then when a 'restart' condition is detected I would have to start up the restarting program, shut down the actual application. Also, I would loose all ability to keep state information over how many times I have had to do this. Finally, there would be perceptible flicker as the application shuts down and restarts - that's unacceptable for the type of application that this is. So yeah, while I understand why you would ask that, I've discussed the issue with several people and this was the simplest solution that we had. (The more complicated solution is to create a ResetRegistrar object that all objects register themselves with and that will call a Reset() method for each object when a reset condition is met).
-
Well yes, there's a couple other issues. Essentially, in order to do this I would have to create another program which would have as its sole duty restarting the application, then when a 'restart' condition is detected I would have to start up the restarting program, shut down the actual application. Also, I would loose all ability to keep state information over how many times I have had to do this. Finally, there would be perceptible flicker as the application shuts down and restarts - that's unacceptable for the type of application that this is. So yeah, while I understand why you would ask that, I've discussed the issue with several people and this was the simplest solution that we had. (The more complicated solution is to create a ResetRegistrar object that all objects register themselves with and that will call a Reset() method for each object when a reset condition is met).
Okay. In that case I suggest you use the Observer Pattern for your solution. Using this pattern everything should be pretty neat and somewhat easy to implement.
-
Okay. In that case I suggest you use the Observer Pattern for your solution. Using this pattern everything should be pretty neat and somewhat easy to implement.
Yup, that's what I was thinking before this solution with application domains was proposed to me on the ALT.NET list. I thought it was pretty nifty and would give me an oppurtunity to learn something new. Are you saying that its not possible?
-
Yup, that's what I was thinking before this solution with application domains was proposed to me on the ALT.NET list. I thought it was pretty nifty and would give me an oppurtunity to learn something new. Are you saying that its not possible?
Togakangaroo wrote:
Are you saying that its not possible?
Never said that. Your app which is talking to db will be the observable and the restarter will be the observer using the observer pattern.