Skip to Content
author's profile photo Former Member
Former Member

Apparent freezing of an application during an involved large loop

I have an issue with a progress bar and progress microhelp 'freezing' mid-processing during a loop that could vary up to 70,000 rows.

The loop in some instances could take up to 5 minutes to process and, if the progress bar and microhelp 'freeze', it gives the User the impression the application has crashed. Yet the application is still peddling away 'behind' the Window and will process if given time, although 5min before a computer screen is a long time.

I am using PB 12.5 classic on Windows 8 - the problem occurs both in the development and executional mode

I have used a Yield() statement. This is the loop code, excluding the primary processing code - the primary code is essentially creating entity relationship links and loading them into a temporary table.

FOR ll_count = 1 TO ll_rows

Yield()

If MOD(ll_count,20) = 0 Then

If IsValid(ahpb_progress) then

li_percentage = INT((ll_count / ll_rows) * 100 )

ahpb_progress.position = li_percentage

gnv_app.of_GetFrame ().SetMicrohelp ( "Processing row " + String ( ll_Count ) + ", please wait..." )

End if

End If

....

....

....

NEXT

Any advice on how to stop the apparent 'freezing' would be appreciated.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Jul 27, 2016 at 07:48 AM

    Hi William,

    Yield() should be the right way. Maybe the other functionality in the loop (...) is to slow so yield() is not running often enough? Try to add additional yields().

    And try this instead of a single Yield() call:

    DO WHILE Yield()

    LOOP

    It yields until there are no more messages in the queue.

    But be carefully with yield! If someone tries to close your window or the app if you are in the loop you will get errors. So you should not allow that in this case.

    HTH,

    René

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2016 at 04:32 PM

    Might be just slow and not really freezing.

    Try to move the microhelp out of the IF and see if it stops updating.

    You can also call gnv_app.of_getFrame just once, not in the loop

    w_frame lw_frame

    lw_frame = gnv_app.of_GetFrame ()

    FOR ll_count = 1 TO ll_rows

    Yield()

    If MOD(ll_count,20) = 0 Then

    If IsValid(ahpb_progress) then

    li_percentage = INT((ll_count / ll_rows) * 100 )

    ahpb_progress.position = li_percentage

    End if

    End If

    lw_frame.SetMicrohelp ( "Processing row " + String ( ll_Count ) + ", please wait..." )

    ....

    ....

    ....

    NEXT

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2016 at 11:58 PM

    Hi Bill,

    Yield() is good start, however, the problem is that your gui and process runs in same single thread.

    You have a choice of running your process in a separate thread or it might be easier to have the progress bar run in a separate thread:

    Progress information in a shared object.

    I can dig out the code for you and help inflict it. You have my details.

    Lars

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2016 at 02:47 AM

    Hi William;

    I wonder if the Modulus function is the source of your problems when the ll_count gets too large (just a guess). Maybe saving the % to another variable & displaying the progress when the current % is > 1 over the saved %.

    Just a random thought.

    Regards ... Chris

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2016 at 10:18 AM

    Thank you all for your guidance. I included some extra 'Yield()s' and the DO WHILE loop suggested by Rene, and replaced the MOD with code as suggested by Chris.

    I processed some large files that took over five minutes to loop through and could not reproduce the problem - to which I should add that the problem as it was before was random and did not regularly occur. Hence I did not have the opportunity to trial Neil's suggestions (although I am certain from past testing from the references to the Task Manager, or waiting out a result, that the application was still processing).

    Thanks also to Lars who kindly gave me a .pbl with a neat process bar - I still haven't had the chance to get my head around it yet, nor 'multithreading' which again, Lars kindly explained to me.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.