Search code examples
c#dllprogramming-languagesevent-handling

C# "Persistent" call to DLL


I am calling a method from a self made DLL. This method triggers an event and it is raised by an EventHander inside the class.

The problem is that the control of the execution returns to the main program (WebClass in the diagram) which makes the call to the class before the eventhandler is able to catch the event.

Here is a little diagram of how it should work http://dl.dropbox.com/u/5654637/model1.png

And this is what it actually does http://dl.dropbox.com/u/5654637/model2.png

Is there a way to make the call to the class' method and make sure it will execute all tasks before returning control to the caller?

Thanks


Solution

  • I'd have to see what it happening inside your other DLL. By default, it should work as you want. Unless you do something to make it asynchronous, events in .NET are synchronous. When you fire an event, the code that fires that event will not continue to execute until all delegates that are listening to the event have been executing to completion (or one of the delegates throws an exception).

    Saying that the code "waits" until the delegates are finished executing isn't even an accurate statement, an event can be thought of as a collection of delegates, and when an event is fired, it loops through all of the delegates and executes them one at a time.