Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: Progress Bar status indicator

Unread post by Martin Meyer »

Yes. I have changed the example to use the application windows status line as a load indicator. Now the example displays only a text on the status bar, but that is for what Loffy has asked for.

I have tried to use terminate/1 and close/0 to cancel the thread when the formWindows close button is clicked. But that has led to the application hanging after closing some formWindows. Is there some 'trick' how to properly terminate threads?

Do you see further issues in the example which should be improved or does the example look all OK now?
Attachments
Progress Example 3.zip
(24.24 KiB) Downloaded 362 times
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Progress Bar status indicator

Unread post by Thomas Linder Puls »

I think it looks fine. You should notice that it is not necessary to guard random with a critical section, it is already guarded internally.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: Progress Bar status indicator

Unread post by Martin Meyer »

I took the critical section out and played a bit. Starting a bunch of dealers, closing a lot, and again starting some... That game did not take long until I got an exception:
===== 2019-10-28 23:22:45 =======================


----------------------------------------
System exception

error code = 1
ExtraInfo = Exception C0000005: Access violation

systemException (runtime_exception)
runtime_exception::runtimeExceptionRaiser
pfc\exception\runtime_exception.pro(21,65)
----------------------------------------
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipRun.dll (0x0000001414512AA6)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x0000001414009C8A)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\Progress Example.exe (0x00000001403A48A8)
C:\WINDOWS\SYSTEM32\ntdll.dll (0x00007FFA78985013)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipRun.dll (0x0000001414515457)
c:\program files (x86)\visual prolog\build 902\ce\pfc\gui\window.pro(955)
c:\program files (x86)\visual prolog\build 902\ce\pfc\gui\window.pro(1967)
c:\program files (x86)\visual prolog\build 902\ce\pfc\gui\guisupport\toplevelcontainerwindowsupport.pro(105)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x000000141400AB77)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipVpi.dll (0x0000000115317124)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipVpi.dll (0x000000011531A447)
C:\WINDOWS\System32\USER32.dll (0x00007FFA77977E6F)
C:\WINDOWS\System32\USER32.dll (0x00007FFA77966C8F)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x00000014140071C0)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x00000014140071C0)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x00000014140071C0)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x00000014140071C0)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x00000014140071C0)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x00000014140071C0)
c:\program files (x86)\visual prolog\build 902\ce\pfc\application\exe\mainexe.pro(19)
main.pro(11)
C:\WINDOWS\SYSTEM32\ntdll.dll (0x00007FFA789892AC)
C:\WINDOWS\System32\KERNELBASE.dll (0x00007FFA75A11EDB)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\Progress Example.exe (0x00001A80D7EA0A39)
OS: Windows 10.0 Version 1903 (OS Build 18362.418) Windows 10 Pro
And from another try:
===== 2019-10-28 23:32:04 =======================


----------------------------------------
Bad window handle

ExtraInfo = Window handle is invalid : '00000000000209E0'
error code = 6000

vpi_WinBadHandle (vpi)
vpi::vpiExceptionRaiser
pfc\vpi\vpi.pro(242,9)
----------------------------------------
c:\program files (x86)\visual prolog\build 902\ce\pfc\exception\exception.pro(212)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipKernel.dll (0x000000141400997F)
c:\program files (x86)\visual prolog\build 902\ce\pfc\exception\exception.pro(207)
c:\program files (x86)\visual prolog\build 902\ce\pfc\vpi\vpi.pro(242)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipVpi.dll (0x0000000115317250)
C:\Users\Martin\Projekte\VIP\9.0\mfc prod\Demo\Progress Example\exe64\vipVpi.dll (0x000000011531A447)
dealerform\dealer_onprogressupdatectl.pro(26)
domainlogic\dealer.pro(61)
c:\program files (x86)\visual prolog\build 902\ce\pfc\windowsapi\exe_api\exe_api.pro(51)
c:\program files (x86)\visual prolog\build 902\ce\pfc\multithread\thread.pro(40)
OS: Windows 10.0 Version 1903 (OS Build 18362.418) Windows 10 Pro
I have put the critical section in again and stressed the system in same way as before. That also led to exceptions. I suppose the critical section has no influence on the exceptions.

I suspect that the problem is caused in somehow by the callback predicate onProgress/1 when the dealerForm is just about to be destroyed. Maybe the calls

Code: Select all

        dealerForm:state_ctl:setText(StateStr),         dealerForm:deck_ctl:setText(DeckStr),         dealerForm:progress_ctl:progress := DonePct,
are running into a problem when the dealerForm is already, or maybe partly, destroyed?
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Progress Bar status indicator

Unread post by Thomas Linder Puls »

Working with multiple threads has that kind of synchronization problems that you mention and that is why it is not simple to shift work into separate threads. To enable premature termination of a background task, it is of course necessary to ensure that the termination is carried out is a safe order. For situation like this we can either ensure that the controls are not updated after they have been destroyed or that they are not destroyed until the background task has actually terminated.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: Progress Bar status indicator

Unread post by Martin Meyer »

The easiest way to solve the synchronization problem is probably to wrap the calls to the dealerForm controls in postAction calls:

Code: Select all

        dealerForm:postAction({  :- dealerForm:state_ctl:setText(StateStr) }),         dealerForm:postAction({  :- dealerForm:deck_ctl:setText(DeckStr) }),         dealerForm:postAction({  :- dealerForm:progress_ctl:progress := DonePct }),
Done that I have not got exceptions anymore. I think I have learned a lot and the example is perfect now. I upload it once again for Loffy and thank you Thomas for the great support.

One remark: The critical section can also be removed from the multiThreadDemo in the examples when it is not necessary (anymore) to guard random with a critical section.
Attachments
Progress Example 4.zip
(24.16 KiB) Downloaded 368 times
Regards Martin
Loffy
Active Member
Posts: 47
Joined: 15 Aug 2019 11:32

Re: Progress Bar status indicator

Unread post by Loffy »

Martin and Thomas,

Thank you for all the work you put into this.

After I finish my current test activity I will attempt to merge your solution into my project.

Regards,

Loffy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Progress Bar status indicator

Unread post by Thomas Linder Puls »

It is sufficient with one postAction:

Code: Select all

        dealerForm:postAction(             {  :-                 dealerForm:state_ctl:setText(StateStr),                 dealerForm:deck_ctl:setText(DeckStr),                 dealerForm:progress_ctl:progress := DonePct             }),
Regards Thomas Linder Puls
PDC
Loffy
Active Member
Posts: 47
Joined: 15 Aug 2019 11:32

Re: Progress Bar status indicator

Unread post by Loffy »

Thomas,

Thanks.

I will try to implement the solution over the weekend. I must admit that I had not expected to get this deep into VIP this quickly.

I continue to learn "stuff" in my project and still have a quite a way to go.

Thanks again to yourself and Martin for the determination to attain an outcome.

Regards,

Loffy
Post Reply