How can we stop the current execution of program on button click?

Hi all,
I have following scenario:

  1. Button “Process” - On click button process it is manipulating document.
  2. Button “Cancel” - On click button cancel, I want to stop the execution of program, which is happing on button Process click.
    Earlier I was reloading the plugin to stop execution( window.location.reload() ).
    Is there any way to stop it?

If you’re doing doc manipulation, you must run it in executeAsModal(), which shows a progress bar when it takes longer than a couple of seconds and there’s a Cancel button, which, when clicked, cancels script execution. Are you saying that button isn’t working?

No, I have implemented a custom Cancel button and want to stop program execution on click of that Cancel button.
Can we do this?

I don’t think there’s a way (there was a topic somewhere here about this). But you wouldn’t be able to access your button while progress bar is shown in modal execution anyway, would you? :thinking:

Yes, I am able to access button because plugin is doing some API call, so things are happing in asynchronous way. That is why I have implemented custom progress bar and cancel button.