Ways to shorten iLogic running time & to stop while iLogic is running

Ways to shorten iLogic running time & to stop while iLogic is running

wenhao.leowSLUZJ
Explorer Explorer
821 Views
4 Replies
Message 1 of 5

Ways to shorten iLogic running time & to stop while iLogic is running

wenhao.leowSLUZJ
Explorer
Explorer

Hi, 

 

Just want to ask if there's any way to shorten iLogic running time? And also, because the iLogic running too long, are there any way to stop when the iLogic is running? Really appreciate the help!

0 Likes
822 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

Could you provide more information on what the rules are doing. Some images and dezcriptions of the task being carried out and the code which is being used. Generally there is no magic button to exit a rule but you could build in checks along the way to exit if certain criteria is met. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 5

wenhao.leowSLUZJ
Explorer
Explorer

Hi, 

 

Thank you for the reply.

'Generally there is no magic button to exit a rule but you could build in checks along the way to exit if certain criteria is met.' May I know how to build in the checks? Thank you. 

 

Regards,

Wen Hao

0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor

This would all depend on what your processing. Can you provide an ilogic rule and the issues it has such as takes too long or is freezing etc. The methods could involve counters, timers or error checks. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 5

JelteDeJong
Mentor
Mentor

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.

JelteDeJong_0-1657915746098.png

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.

EESignature


Blog: hjalte.nl - github.com