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#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
Threadto do the work, drops a worker intoThreadPool, or invokes another method to handle the work asynchronously via aDelegateusing 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.