Thanks Matthew,
you are right. Although it is strange that it worked for me in 2017. I used it in the IExternalApplication and the IExternalEventHandler.
I will try to solve my case in different way.
Thanks for your support.
"Have you tried running the macro natively (not in a Visual Studio debugging context)?
[I have had a Thread error similar to this when doing something as simple as showing a TaskDialog during onstartup. When I'm not using Visual Studio, the thread exception doesn't occur.]"
Same situation in my case, without VS everything is fine.