1

Is it possible to write custom events that can be handled by 3rd party applications?

We have an existing app and we're finding that many people that use the app are using sql triggers to custom-write functionality of their own certain when things happen in our app.

This has led to some instances where our own processes have slowed down due to shoddy 3rd party Triggers that block our app.

I was thinking we could make this easier for 3rd party devs if we could raise events that they could handle in their own services or apps instead of having to use triggers.

That way we'd lose the blocking because we can just fire the event and continue. Also their slowness/potential crashes would happen outside of our process.

A) is this a reasonable approach?

B) Is this possible? Can I scope an event beyond the scope of my app?

EDIT

I have since found other related questions to be of interest:

  1. wcf cross application communication
  2. Interprocess pubsub without network dependency
  3. Listen for events in another application (This seems very close to what I'm after)

I guess I'm looking for the simplest approach but if we wanted to adopt this method across a number of other apps within our company we'd have some further challenges:

We have some older apps in vb6 and delphi - from those I'd just like to be able to listen for their events in my (or 3rd party) newer C# apps or services.

For now, I'll look at: Managed Spy and http://pubsub.codeplex.com

Community
  • 1
  • 1
Nils
  • 1,237
  • 3
  • 11
  • 28
  • 1
    I think it's possible, but they would need to be located in an external assembly, which you should share with 3rd party devs. I'd like to know myself how to do that. – Krzysztof Jabłoński Sep 20 '12 at 10:13
  • 2
    Events may not be the best way to do this, especially if your application runs as an executable or service. Take a look at [Managed Extensibility Framework](http://msdn.microsoft.com/en-us/library/dd460648.aspx) – John Saunders Sep 20 '12 at 10:19

2 Answers2

1

No, events are only usable by code that's loaded into your own process. If you don't trust these people now, you really don't want to expose yourself to shoddy code that you load into your own process and throws unhandled exceptions that terminate your app. You'll get the phone call, not them. Besides, they'll use such an event to run code that slows down your app.

In general, anything you do with a dbase will run with an entirely unpredictable amount of overhead. Not just because of triggers added by others, the dbase server could simply be bogged down by other work and naturally slow down over time as it stores more and more data. Make sure that doesn't make your app difficult or unpleasant to use, dbase operations typically must run on a worker thread or be done asynchronously with, say, BeginExecuteXxxx(). And make it obvious in your UI that progress is stalled by the dbase server, not by any code that you wrote. Saves you from having to do a lot of explaining.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

What you're looking to do is basically to send messages to other processes. For this, you need some sort of IPC mechanism. Since it sounds like you'll have multiple listeners to each message, a mailslot is probably the best way. Unfortunately, .NET doesn't have built-in support for mailslots, so you'll have to use P/Invoke.

If you're looking for a built-in solution, then you could use named pipes, WCF, .NET Remoting, or bare TCP or UDP. With any of these, though, you'll have to loop through all of your listeners and send the message one at a time to each of them, which is not that big of a deal, but maintaining the separate connections is a little more of a hassle.

Note that with WCF and .NET Remoting, you're pretty much limiting your clients to using .NET as well. If your clients might be native or some other platform, then mailslots, named pipes, and TCP/IP are your best bet.

P Daddy
  • 28,912
  • 9
  • 68
  • 92
  • Thanks for this, I'll give it a try. I found this which may help others: http://csharpmailslots.codeplex.com/ – Nils Sep 25 '12 at 09:15