it depends on what are you doing. Is it one function that takes so long time, then you can't stop it. Otherwise look at https://www.dotnetperls.com/backgroundworker-vbnet or Cancel an Async Task or a List of Tasks (Visual Basic) | Microsoft Docs. Easiest would be usage of messagebox "Are you sure?"
As I have understood information in your links:
background worker works only with form or I am wrong? If I right, this solution possible if there no other solutions. And still I’m not sure about it. I have tried windowshook and events to cancel it on keystrokes. I have succeed... cancel command and whole addin at the same time.... and solidworks (solidworks exited cause error after addin break). I’m afraid same result.
The other link is not fully clear for me. Should I start async task to listen what hapens in main sub or the main sub must run as task? Anyway, i am not sure it will cancel just the sub or whole addin.
Such solution types is realy new for me and i am sure i am look like a beginer.
I think, I need create some background listener which trows exception on keyboard event. But it is not for my skills.
the schematics of my any main sub:
dim SomeMyvariable as SomeMytype
ColectInfo (SomeMyvariable) 'somemyvariable goes byref
'there can be more sub procedures or functions
background listener can listen only main sub. after triger from keyboard and catch exception it should exit sub.