I am raising an event from managed C++ which is handled by a C# app. Is the C# event handler executed on the same thread it was raised from C++ ??
In other words, Is raising event blocking for C++ until it is completely handled by C#?
I am raising an event from managed C++ which is handled by a C# app. Is the C# event handler executed on the same thread it was raised from C++ ??
In other words, Is raising event blocking for C++ until it is completely handled by C#?
Yes. Extra text to get around the length limit :)
And I had to pass an "I'm Human" test!
Event handler invocation is synchronous by default in .NET, and since your code is both Managed C++ and C#, it is all ".NET".
If you wish your event handlers to function asynchronously, you could simply attach a handler on the C# side that either starts another Thread
to do the work, drops a worker into ThreadPool
, or invokes another method to handle the work asynchronously via a Delegate
using asynchronous programming. The handler would then return quickly, allowing the C# work to execute in the background while the MC++ code can continue invoking other listeners of the event.
Make sure that if you do execute the code that actually handles the event asynchronously, that the C++ code does not expect data in the event arguments to be modified by the handlers. This would be the case if something like CancelEventArgs were used.