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
B

Benny_Lava

@Benny_Lava
About
Posts
74
Topics
61
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Robust plugin system
    B Benny_Lava

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

    C# tutorial question asp-net json help

  • Robust plugin system
    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.

    C# tutorial question asp-net json help

  • Application Crashes during AppDomain.Unload [modified]
    B Benny_Lava

    Hi, After a session of debugging using all advices I collected, here are my findings (So everybody can learn from my mistakes... :) ) -A plugin can be unloaded from a different thread (other thread then the one that spawned it -The problem was that I also handled UnhandledException event of the AppDomain, and a series of unfortunate events happened: *I have 2 mechanisms for protecting my core system from plugins: 1. A watchdog timer mechanism that terminates a plugin if the plugin hasn't responded (raised an watch dog timer event) for a certain period of time 2.A UnhandledException event handler for when an unhandled error occurs in the plugin, and in that event i call UnloadPlugin function and remove the plugin from the core system So a plugin spawned an unhandled exception the same time the watchdog timer called UnloadPlugin function... And in the UnhandledException handler it tried to use data and unload an already unloaded AppDomain So the solution is to develop some kind of synchronization mechanism so if one request for termination comes that no other request are processed. So the bottom line is "Threads are evil" ;) Thanks for your help.

    C# help

  • Application Crashes during AppDomain.Unload [modified]
    B Benny_Lava

    Hehe, Thanks, I stand corrected and my post also... :)

    C# help

  • Application Crashes during AppDomain.Unload [modified]
    B Benny_Lava

    Hi, That sounds like the problem to me. What's probably happening is the domain is getting unloaded while its event handler is still running, and that's confusing the CLR at a level below your exception handling. Yes, that crossed my mind the minute the bug appeared, but the event handler adds the method to a method execution queue I designed and that queue is run in a separate thread, so the event handler 100% exits. By crash I mean when i'm in debugging mode after i press step over over the AppDomain.Unload the debugging session ends and the application literally crashes... :) The plugins do not unload themselves, a dedicated method execution queue runned by a thread that is created in the main AppDomain terminates them by processing the method I posted in the original post. Thank you for your quick reply.

    C# help

  • Application Crashes during AppDomain.Unload [modified]
    B Benny_Lava

    Hi, Thanks for your reply, i'll try removing the UhandledException unsubscription. P.S Sorry i didn't put the code in a code block, I know about it just forgot to use it :)

    C# help

  • Application Crashes during AppDomain.Unload [modified]
    B Benny_Lava

    Hi, I have a very strange problem, i have multiple AppDomains (plugin system). Now at one point i raise an event from one of the plugin domains and the main AppDomain catches the event and calls another function in a seperate thread that Unloads the calling AppDomain. The first thing that came to my mind is that the plugin domain somehow became the main application domain but it didn't i checked before the culprit line below for AppDomain.FriendlyName and it was different than the main application domain. code:

    private void UnloadDevicePluginDomain(DevicePlugin d)
    {
    Guid id = Guid.NewGuid();

            try {
                lock(locker\_) {
                    if(d == null)
                        return;
                    id = d.DevicePluginId;
                    if(d.PluginDomain != null) {
                        //--Just to be on the safe side call plugin Dispose before App domain unload
                        if(d.DeviceInterface != null) {
                            d.DeviceInterface.Dispose();
                        }
    
                        if(d.WatchDogTimer != null)
                            d.WatchDogTimer.Dispose();
    
                        d.PluginDomain.UnhandledException -= new UnhandledExceptionEventHandler(DevicePluginCrashed);
    
                        AppDomain.Unload(d.PluginDomain);   //THE WHOLE APPLICATION CRASHES AT THIS LINE
                        devicePlugins\_.Remove(d);
                    }
                }
            } catch (Exception ex) {
               // DOES NOT COME TO THIS PART
            }
        }
    

    So the weird thing is that there is an exception handler and the line nonetheless crashes the whole application. Any help greatly appreciated. Thanks.

    -- Modified Wednesday, April 13, 2011 3:39 PM

    C# help

  • Execute cross-app domain code
    B Benny_Lava

    Hello, This is the situation I have an assembly A (plugin) loaded into separate app domain, that assembly fires a couple of events. And i have a class B created using the default App domain. Now Class A raises and event and event handler in class B catches that event, but since it is called from another App domain (A) it cannot see variables of app domain B (all variables are null) in this case a public static object that is 100% not null on app domain B. I think i understand why the variable is null, but how do i execute event handler code in app domain B so that code executed in app domain B will see the variables initialized? I have tried CrossAppDomainDelegate but it can only call mehods that don't have any parameters, and since this is an event handler it has parameters and not standard event signature but with a custom EventArgs. How can i solve this problem. Thank you!

    C# question help

  • Protecting from plugin crashes
    B Benny_Lava

    Thank you I will try that.

    C# asp-net database hardware help question

  • Protecting from plugin crashes
    B Benny_Lava

    Hello, I'm building a plugin system for a hardware communicator system. So a plugin is actually a device communicator and the core program has many plugins that communicate with devices and write something to the database. Now, I have solved many things, I have made a DevicePlugin interface and have dynamically loaded and instantiated the plugins, and it works. The only thing that is bothering me is plugin crashes, for some reasons a plugin can sometimes crash (throw an unexpected exception) and a single plugin can crash my entire system. So my question is is there some way to put the entire plugin assembly intoa try catch so when plugin crashes the core system remains intact. Any help greatly appreciated. Thanks!

    C# asp-net database hardware help question

  • C# Polymorphic object comparison
    B Benny_Lava

    The work with polymorphic objects after comparison is very clear to me. I just didn't know how to compare them in C#... Thanks!

    C# csharp tutorial question

  • C# Polymorphic object comparison
    B Benny_Lava

    Thank you!!

    C# csharp tutorial question

  • C# Polymorphic object comparison
    B Benny_Lava

    Hi, Let's say there are 3 objects: Class A Class B : A Class C : B I want to pass through all objects that derive from Type B C obj1 = new C(); B obj2 = new B(); if(obj1.GetType() == typeof(B)) { //--Pass through all objects that derive from object B or object A... } typeof comapares directly the top types C must equal C... No polymorphic comarison... How to do a polymorphic comparison? Which keyword or mechanism to use? Thanks!

    C# csharp tutorial question

  • AsyncCallback problem?
    B Benny_Lava

    Hi, I have a method which is in another project (but in the same solution), I create a delegate to that method and then use delegate.BeginInvoke to Asynchronously call that method and the callback method is in the calling project. Now the problem is when the invoked method completes, I need to somehow signal the callback method if the invoked method has succedded True or False, and because the invoked method is in another project and the calling method is also in another project and this project has a reference to the invoked method project if I try to set some variable in the calling project from invoked method project I can't because i don't have a reference to this project and if I try to reference the project i get a circular dependency error.. which is resonable... This is the code:

    private delegate void edi2xml_delegate(object ar);
    private edi2xml_delegate edi2xml_del;

    public void convert_file(object async)
    {
    DemoApplication.edi_test edi2xml_converter = new DemoApplication.edi_test();
    edi2xml_converter.file_path = pub.def.edi_file_directory + "\\" + file_list.file_name;

       edi2xml\_del = new edi2xml\_delegate(edi2xml\_converter.convert);
    
       //--This is the invoking
       edi2xml\_del.BeginInvoke(null, import\_xml2db, (string)(pub.def.edi\_file\_directory + "\\\\" + file\_list.file\_name + ".xml"));
    

    }

    private void import_xml2db(IAsyncResult ar)
    {
    //--In this callback method i need to get the return state of the invoked method
    string full_path = (string)ar.AsyncState;

       edi2xml\_del.EndInvoke(ar);  
    

    }

    //--This function is in another project (another assembly) so I can't set some bool variable in the other project because i would get circular dependency error

    public void edi2xml()

    {
    //--Here I need to somehow signal the import_xml2db method(the callback method) that i have succeded or not (true-false)

    }

    Any help or suggestions greatly appreciated.

    C# help xml question

  • Embedded resource problem
    B Benny_Lava

    Hi, I have created a custom resx file. And I am trying to add it to my project as embedded resource... There are two identical files (except for the file name) prolang.cz.resx prolang.hr.resx prolang.cz.resx is embedded OK (checked it with MSIL dissambler) but the other one just won't... I have tried cleaning, restart IDE, restarting computer, deleting bin and obj folders... no luck. Any ideas? Thanks.

    Visual Basic visual-studio hardware help question learning

  • Inheriting a class or implementing a interface...
    B Benny_Lava

    Hi, I have a public partial class "con_param_tou : UserControl" (standard userControl) But i want to inherit or implement a interface of a class that i build. So i want to maintain the designer mode of standard User Control but i also want to implement or inherit one of my classes. My class is currently declared as public interface base_param_interface (because I know that i cannot inherit multiple classes... So what I want to do is inherit UserControl and implement one of my interfaces which has a couple of public properties and 2,3 functions... How do I do that? Thanks in advance!

    C# question

  • "Windows has triggered a breakpoint" error.
    B Benny_Lava

    Hi, I have 2 forms, (frm_main and frm_meter) frm_main has a menuStrip control with a New File menu, When I click the menu i create a new variable (meter_control) of type frm_meter and execute meter_control.show(); The problem arrises when I click once on the menu, then I close the meter_control form and then click again. and then The error "Windows has triggered a breakpoint" shows... here is the code Public frm_main() { InitializeComponent(); this.menuStrip_newFile.Click += new EventHandler(menuStrip_newFile_click); } private void menuStrip_newFile_click(object sender, EventArgs e) { frm_meter meter_control = new frm_meter(); meter_control.Show(); // Here it sets the green breakpoint - the second time I try to create this variable after just closing it } The total error description is: Windows has triggered a breakpoint in micro_param.exe. This may be due to a corruption of the heap, and indicates a bug in micro_param.exe or any of the DLLs it has loaded. The output window may have more diagnostic information In the output window this is written: "HEAP[micro_param.exe]: HEAP: Free Heap block ff2028 modified at ff205c after it was freed" PS. I do not load any of DLL-s Thanks.

    C# help debugging

  • Setting background color or image to individual cells in a data Grid view?
    B Benny_Lava

    Hi, I have a cellMouseClick event on my dataGridView. When I click a mouse on a individual cell, based od cell index I must set a background color or an image on a individual cell? I know that this is possible on an entire column. But on a individual cell? Thank you!

    Visual Basic css database question

  • MD5 algorithm for 8-bit microcontrollers?
    B Benny_Lava

    the title says it all. Any help greatly appreciated

    Managed C++/CLI algorithms help question

  • Win XP accept incoming connections. From CHAP to PAP?
    B Benny_Lava

    Hi, I have setup a Windows XP dial-up server(Control Panel->Networking->New Connection->Advanced->Accept Incoming connections). The connection works but the server (XP machine) uses CHAP protocol for authentification. How do I change it to PAP(it must be PAP)? Thank you!

    System Admin question sysadmin workspace
  • Login

  • Don't have an account? Register

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