Page 3 of 3

Re: Progress Bar status indicator

Posted: 25 Oct 2019 18:42
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?

Re: Progress Bar status indicator

Posted: 28 Oct 2019 10:52
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.

Re: Progress Bar status indicator

Posted: 28 Oct 2019 23:47
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?

Re: Progress Bar status indicator

Posted: 30 Oct 2019 12:22
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.

Re: Progress Bar status indicator

Posted: 31 Oct 2019 0:21
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.

Re: Progress Bar status indicator

Posted: 31 Oct 2019 3:15
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

Re: Progress Bar status indicator

Posted: 31 Oct 2019 9:27
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             }),

Re: Progress Bar status indicator

Posted: 31 Oct 2019 10:52
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