Loading and communicating between and unloading 2 appdomains in one process

Last post 05-11-2008 7:56 AM by mbanavige. 1 replies.

Sort Posts:

  • Loading and communicating between and unloading 2 appdomains in one process

    05-09-2008, 9:18 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 indeed 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();
        }
      }
    

    3) 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. 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 yourself at your mercy. Am I missing anything here? Is this how you would do it? Is there any online tutorials you guys can recommend?

  • Re: Loading and communicating between and unloading 2 appdomains in one process

    18 hours, 57 minutes ago
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs
    These forums are for ASP.NET (web sites / web applications), not windows applications. You might try your question at the MSDN Forums which deals with Windows Applications written for .NET.
    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (2 items)