Asked by:

Application crash when using WorkItemHandler from C++ that handles exceptions

General discussion

I have a simple setup, with a main C# project (Windows Store) that uses a C++ Windows Runtime Component.

What I've found is that, whenever I use the WorkItemHandler from within C++ and an exception is thrown and catched inside the handler code, the termination just fails with a crash somewhere inside threadpoolwinrt.dll.

The code is pretty simple. In the C#project, as a response to an item click, I'm just invoking an static class method from C# like:

No matter how I play with the options passed to the ThreadPool::RunAsync method, the code inside the lambda function executes normally; the exception is thrown and correctly catched; but when the WorkItemHandler terminates (when it's actually destroyed after
the task has been completed) the application just crashes.