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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Robust plugin system

Robust plugin system

Scheduled Pinned Locked Moved C#
tutorialquestionasp-netjsonhelp
4 Posts 3 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.
  • B Offline
    B Offline
    Benny_Lava
    wrote on last edited by
    #1

    Hi, I know I posted a similar question a couple of days ago and I'm sorry about that but i'm going crazy about this problem... So I will simplify the scenario. I am developing a plugin system for a windows service application. The plugin system has been developed with the AppDomain paradigm. I won't get into details of how my system works, but will demonstrate in a simple code example (of which I tried

    //--This is an external assembly project (.dll)
    namespace Foo
    {
    [Serializable]
    public class Foo
    {
    Thread workThread_;

        public void Initialize()
        {
            workThread\_ = new Thread(new ThreadStart(DoWork));
            workThread\_.Start();
        }
    
        public void DoWork()
        {
            int i = 0;
    
            while (i < 500)
                i++;
    
            throw new Exception("Unhandled exception");
        }
    }
    

    }

    namespace AppDomainTest
    {
    public class Bar
    {

        AppDomain new\_domain;
    
        public Bar()
        {
           
        }
    
        private void new\_domain\_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
           //--Cleanup new\_domain and dispose it
            new\_domain = null;
        
        //--After this event handler finishes so the main application process finishes although the event handler is subsrcibed on foo\_test
        }
    
        public void InitializeBar()
        {
            Foo.Foo foo\_test;
    
            new\_domain = AppDomain.CreateDomain("Auxilary domain");
            foo\_test = (Foo.Foo)new\_domain.CreateInstanceFromAndUnwrap("Foo.dll", "Foo.Foo");
            
            new\_domain.UnhandledException += new UnhandledExceptionEventHandler(new\_domain\_UnhandledException);
    
            foo\_test.Initialize();
        }
    }
    

    }

    I kept reading about AppDomains and how they are great for plugins and isolation and stability etc... but when the plugin has UnhandledException the whole application crashes with its main AppDomain crashing... In my case a plugin can spawn multiple threads to do its work and those threads never interact with the core system, only through raising plugin events... So my question is how to really protect from plugin failures (Unhandled Exception), so when 1 plugin crashes the rest of the application remains intact (continues to run) bearing in mind that a plugin can spawn multiple threads to do its work? Thank you!

    See the world in a grain of sand.

    B 1 Reply Last reply
    0
    • B Benny_Lava

      Hi, I know I posted a similar question a couple of days ago and I'm sorry about that but i'm going crazy about this problem... So I will simplify the scenario. I am developing a plugin system for a windows service application. The plugin system has been developed with the AppDomain paradigm. I won't get into details of how my system works, but will demonstrate in a simple code example (of which I tried

      //--This is an external assembly project (.dll)
      namespace Foo
      {
      [Serializable]
      public class Foo
      {
      Thread workThread_;

          public void Initialize()
          {
              workThread\_ = new Thread(new ThreadStart(DoWork));
              workThread\_.Start();
          }
      
          public void DoWork()
          {
              int i = 0;
      
              while (i < 500)
                  i++;
      
              throw new Exception("Unhandled exception");
          }
      }
      

      }

      namespace AppDomainTest
      {
      public class Bar
      {

          AppDomain new\_domain;
      
          public Bar()
          {
             
          }
      
          private void new\_domain\_UnhandledException(object sender, UnhandledExceptionEventArgs e)
          {
             //--Cleanup new\_domain and dispose it
              new\_domain = null;
          
          //--After this event handler finishes so the main application process finishes although the event handler is subsrcibed on foo\_test
          }
      
          public void InitializeBar()
          {
              Foo.Foo foo\_test;
      
              new\_domain = AppDomain.CreateDomain("Auxilary domain");
              foo\_test = (Foo.Foo)new\_domain.CreateInstanceFromAndUnwrap("Foo.dll", "Foo.Foo");
              
              new\_domain.UnhandledException += new UnhandledExceptionEventHandler(new\_domain\_UnhandledException);
      
              foo\_test.Initialize();
          }
      }
      

      }

      I kept reading about AppDomains and how they are great for plugins and isolation and stability etc... but when the plugin has UnhandledException the whole application crashes with its main AppDomain crashing... In my case a plugin can spawn multiple threads to do its work and those threads never interact with the core system, only through raising plugin events... So my question is how to really protect from plugin failures (Unhandled Exception), so when 1 plugin crashes the rest of the application remains intact (continues to run) bearing in mind that a plugin can spawn multiple threads to do its work? Thank you!

      See the world in a grain of sand.

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      This is exactly what AppDomain.UnhandledException is for, I thought. This post surprises me.

      realJSOPR B 2 Replies Last reply
      0
      • B BobJanova

        This is exactly what AppDomain.UnhandledException is for, I thought. This post surprises me.

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        BobJanova wrote:

        This post surprises me.

        Pretty soon, that will stop happening. :)

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

        1 Reply Last reply
        0
        • B BobJanova

          This is exactly what AppDomain.UnhandledException is for, I thought. This post surprises me.

          B Offline
          B Offline
          Benny_Lava
          wrote on last edited by
          #4

          Yes, I thought that also... but surprise surprise... damned M$ pulled a fast one... But I can't accept that there is no other way to do this in .NET? Which means that AppDomain is actually quite useless if this does not work... I don't see the point of AppDomains if you can't create a plugin system... this is very confusing... Any other ideas?

          See the world in a grain of sand...

          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