2 Replies Latest reply on Jun 25, 2018 9:43 AM by Aleksandras Korolkovas

    How to cancel long lasting addin command

    Aleksandras Korolkovas



      I have developed for company where I’m working, solidworks addin with many commands. Some of them running  3-4 minutes, some, depending on assembly size, up to half hour. Users from time to time clicks these command buttons by mistake. After that they must wait until end. It is because there is no possibility stop addin command in vb.net as it possible with VBA (ctrl+brake). Possibility to kill Solidworks is not an option (couse unsaved work). Any suggestions how to do these extra brake for any or all commands in solidworks vb.net addin?

        • Re: How to cancel long lasting addin command
          Ivana Kolin

          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?"

            • Re: How to cancel long lasting addin command
              Aleksandras Korolkovas

              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:

              sub main()


              dim SomeMyvariable as SomeMytype

              ColectInfo (SomeMyvariable) 'somemyvariable goes byref

              Calculate (SomeMyvariable)

              ExportToExcel (SomeMyvariable)

              'there can be more sub procedures or functions

              end sub


              background listener can listen only main sub. after triger from keyboard and catch exception it should exit sub.