C# - how to loop a command and program user exit via escape button

I'm trying to multiple insert a block/drawing with the possibility to exit the function with the escape button. But I can't get the exit programmed. It works fine without the loop. I have tried several ways, one like mentioned in this Acad post, but can't get it done. Anyone a good idea where to start or how to do it?

This discussion has been closed.