Without any details of your rule, it's in possible to say anything about your rule specific. But in general you may want to read this "Improving Your Program’s Performance".
Stopping a rule is complicated, but there is a "not so magic" button on the progress bar.

Have a look at the following example rule.
Class ThisRule
Private _progressBar As Inventor.ProgressBar
Private _userClickedOnCancel As Boolean = False
Public Sub Main()
_progressBar = ThisApplication.CreateProgressBar(False, 10, "This is your main title", True)
AddHandler _progressBar.OnCancel, AddressOf OnCancel
UpDateProgress("Executing first process")
System.Threading.Tasks.Task.Delay(3000).Wait()
For i = 2 To 10
UpDateProgress("Executing some process: " & i)
System.Threading.Tasks.Task.Delay(1000).Wait()
If UserWantsToCancel Then Return
Next
_progressBar.Close()
End Sub
Private Property UserWantsToCancel() As Boolean
Get
If (_userClickedOnCancel) Then
MsgBox("User clicked cancel and it has been detected now.")
' add code here for clean exit of the rule.
_progressBar.Close()
Return True
End If
Return False
End Get
Set(value As Boolean)
_userClickedOnCancel = value
End Set
End Property
Private Sub UpDateProgress(message As String)
_progressBar.Message = message
_progressBar.UpdateProgress()
End Sub
Private Sub OnCancel()
MsgBox("OnCancel fired. Setting UserWantsToCancel flag.")
UserWantsToCancel = True
End Sub
End Class
Notice the last boolean in the progress bar initialisation line:
_progressBar = ThisApplication.CreateProgressBar(False, 10, "This is your main title", True)
The default value (if you don't set it,) is "False". But by setting it to "True" you will get the cancel button on the progress bar. By default, nothing happens when the user clicks on that button and you have to code that all yourself. Therefore I added an event handler "OnCancel". This event handler will set the property "UserWantsToCancel" to "True". That will not stop the rule but at least we now have a property that will tell if the user wants to cancel.
Now in your code, you need to check if that property is set to "True". If that is the case then you need to stop(/return) your rule. This is done in the example with the line:
If UserWantsToCancel Then Return
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com