Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I need help starting multiple and communicating between application domains [modified]

I need help starting multiple and communicating between application domains [modified]

Scheduled Pinned Locked Moved C#
questioncsharpdatabasewinformshelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Togakangaroo
    wrote on last edited by
    #1

    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();
    }
    }

    1. 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

    C 1 Reply Last reply
    0
    • T Togakangaroo

      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();
      }
      }

      1. 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

      C Offline
      C Offline
      CodingYoshi
      wrote on last edited by
      #2

      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.

      T 1 Reply Last reply
      0
      • C CodingYoshi

        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.

        T Offline
        T Offline
        Togakangaroo
        wrote on last edited by
        #3

        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).

        C 1 Reply Last reply
        0
        • T Togakangaroo

          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).

          C Offline
          C Offline
          CodingYoshi
          wrote on last edited by
          #4

          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.

          T 1 Reply Last reply
          0
          • C CodingYoshi

            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.

            T Offline
            T Offline
            Togakangaroo
            wrote on last edited by
            #5

            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?

            C 1 Reply Last reply
            0
            • T Togakangaroo

              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?

              C Offline
              C Offline
              CodingYoshi
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups