3

While writing this question: AppDomain, handling the exceptions I also thought of a different question.

If you would write a plugin app like I wrote above. Would you go about writing the plugins as executables or as libraries?

How much control would you have over a dynamically loaded executable that is run through the AppDomain.ExecuteAssembly(String) method? instead of creating an instance of an object using AppDomain.CreateInstanceAndUnwrap(String, String).

Where I currently have an interface which features a Start/Run + Stop + Init method that is called after CreateInstanceAndUnwrap. Would you have the same type of control over the executed assembly version? If I would use the latter, how can I achieve such functionality to dynamically stop that plugin?

Or am I thinking in the totally wrong direction?

[edit-after-question]

Basicly we got 'one' application, and multiple functions.

  • Burning a (video) DVD)
  • Printing photo's
  • downloading images from a photo/videocamera
  • a POS
  • a storage server, functioning as a backup/configsettings/image+video repository
  • displaying said photos/videos on a multiple displays
  • and a few others, but these were the main 'functions'

A computer can run multiple tasks/plugins. For instance, we can choose to have one computer handle the whole image download/display/print system. Or have one centralized printing computer with multiple download/display systems.

Everything is communicating over sockets

If a plugin crashes for whatever reason it needs to be restarted and a mail should be send to the office. If the same crash occurs multiple times in a short timeframe then it should send some kind of emergency e-mail and shutdown that plugin and notify the operator.

Some of these functions use thirdparty unmanaged code, some are written in C++/Native and some in C++/CLI others are written in C#, all will be written within the same solution as different projects.

edit2 There is also this additional feature we would like to add to the system. It is to automatically update a plugin as soon as there is a newer version of that plugin available. The parent AppDomain/thread should periodically check for updates and if an update is found it should unload that plugin, download the new version and start it again. For this specific reason I think we need to use AppDomain's

Community
  • 1
  • 1
Daan Timmer
  • 14,771
  • 6
  • 34
  • 66
  • IIRC .NET Exe files are a .NET DLL with a bootstrapper (C++) and a manifest that tells the bootstrapper where the entry point is, among other things like "run me with admin privs" – Aren Aug 15 '11 at 23:50
  • That would depend entirely upon what this 'plugin' needs to do. Care to enlighten us a little more? – csharptest.net Aug 15 '11 at 23:51
  • I've added extra information on your request, @csharptest.net – Daan Timmer Aug 16 '11 at 08:31

2 Answers2

2

I would certainly go with using CreateInstanceAndUnwrap(). You have much more control that way and you can reasonably communicate with the plugin. When you use ExecuteAssembly(), you can pretty much start it and then read the return value (an int).

Also, when using CreateInstanceAndUnwrap(), there is nothing stopping you from using an exe anyway, if you have a good reason to do it.

Basically, you have a working solution and there is no need to change it (at least not in this direction).

svick
  • 236,525
  • 50
  • 385
  • 514
  • I've added extra information. Currently it indeed would be a working solution (We have not yet programmed anything yet regarding the plugins, currently in planning and designing phase) – Daan Timmer Aug 16 '11 at 08:37
0

You should also consider alternative design. Based on this information:

Where I currently have an interface which features a Start/Run + Stop + Init method

...

A computer can run multiple tasks/plugins. For instance, we can choose to have one computer handle the whole image download/display/print system. Or have one centralized printing computer with multiple download/display systems.

...

Everything is communicating over sockets

Communication is already done by sockets, the only missing feature is 'management':

  1. Isolate crashes in one plugin from others.
  2. Start/Stop plugin
  3. Restart plugin on crash
  4. Notify admins about crashes by email
  5. Auto update

You can simply utilize whats already there - windows services. If you deploy plugins as windows services you already have 1, 2 and 3 implemented. You don't have to worry about AppDomains, crashes in native code etc. The implementation is robust, tested and well understood by admins. You can manage windows services programaticaly. The only thing you need to do is write one 'WatchDog' service that will send emails and handle auto updates.

Dmitry
  • 17,078
  • 2
  • 44
  • 70
  • But that features the problem of a GUI. A windows service can not consist of a GUI. – Daan Timmer Aug 16 '11 at 13:39
  • @Daan: yes, in this scenario you would probably need a portal GUI app that will offload its tasks to services. This can be a deal breaker for this architecture depending on complexity. Or you can use regular processes and manage them in WatchDog. – Dmitry Aug 16 '11 at 13:50