1. Ricardo Colarina
  2. PowerBuilder
  3. Monday, 20 January 2020 01:33 AM UTC

Hi All,

I'm using PB 2017 R3 Build 1858 in Windows 8.  I've got an asynchronous report using SharedObject functions.  Data is retrieved using a datastore then is copied into the report datawindow after the datastore has finished retrieve.  When I close the report window while retrieve is still running, the report window closes OK.  However, when I close the application, in the PB IDE, the application freezes.  When running as an EXE, the application closes but remains in the background processes.  Can someone please let me know how I'll be able to terminate the report process?  I don't want to chop the DS retrieval so that the retrieve happens in a loop and makes it easier to properly close the report.

Thanks.

Best regards,

Ricardo

Ricardo Colarina Accepted Answer Pending Moderation
  1. Tuesday, 21 January 2020 03:36 AM UTC
  2. PowerBuilder
  3. # 1

Hi All,

Thanks very much for your responses.  I decided to just add a loop to split-up the data retrieval into chunks and this works.  This also has the added benefit of not stressing the database too much with just one retrieve call.

Cheers.

Ricardo

 

Comment
  1. René Ullrich
  2. Tuesday, 21 January 2020 06:27 AM UTC
If you split the retrieval you may also run the splits in separate threads (shared objects) parallel. This may increase performance.
  1. Helpful
  1. Ricardo Colarina
  2. Tuesday, 21 January 2020 20:37 PM UTC
Thanks Rene. I've split the retrieval according to the PK, and that'll be roughly 2000 rows (depending on other arguments). Is there a limit on the number of separate threads that can be run?
  1. Helpful
  1. René Ullrich
  2. Wednesday, 22 January 2020 06:16 AM UTC
I don' t know about a documented limit. The number of threads should depend on processor cores. To much threads can make the whole process slower so you should try what number is the best.
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Tuesday, 21 January 2020 00:11 AM UTC
  2. PowerBuilder
  3. # 2

I think that as long as a retrieval is in progress, you CANNOT shut down the application or it will terminate the retrieval.

Set up a flag that lets the app know that the reports are still in process/still retrieving, and in the CloseQuery event check the flag. If set, do not allow the app to close.

At the end of the reports process, clear the flag and then close the app.


Olan

Comment
  1. Ricardo Colarina
  2. Tuesday, 21 January 2020 00:58 AM UTC
Hi Olan,



I've already got a flag, but instead of preventing the user from closing the report/application outright, I prompt the user if he/she really wants to stop the report. If the answer is No then I must figure out somehow how to terminate just the retrieval, otherwise I'll just code something that will close the app without freezing when the user exits the application.



Thanks.

  1. Helpful
There are no comments made yet.
Ricardo Colarina Accepted Answer Pending Moderation
  1. Monday, 20 January 2020 20:41 PM UTC
  2. PowerBuilder
  3. # 3

Hi Chris,

I will try this.  I also tried playing with TerminateProcess and TerminateThread, but I can't get both to work.

Thanks.

Ricardo

 

Comment
  1. Chris Pollach @Appeon
  2. Monday, 20 January 2020 22:31 PM UTC
BTW: that Send() is basically a "KILL" process instruction to the O/S.
  1. Helpful
  1. Ricardo Colarina
  2. Monday, 20 January 2020 22:44 PM UTC
Thanks for the info. Just waiting for our sys admin as I can't connect to the database at the moment (service is not running). Both the halt and the send approaches will actually close the application, so I'll still try to somehow terminate the process immediately right after the report window is closed without closing the application.
  1. Helpful
  1. Ricardo Colarina
  2. Tuesday, 21 January 2020 03:34 AM UTC
Hi Chris, I tried both Halt and Send but still no luck.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 20 January 2020 16:46 PM UTC
  2. PowerBuilder
  3. # 4

Hi Ricardo;

  I wonder if the "workaround" solution might be to inform the main task that a DBCancel is in effect and if so, have the main task use a HALT command to clean-up the PB App vs a Halt Close or a Close() command on the main App window.

Regards ... Chris

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 20 January 2020 06:53 AM UTC
  2. PowerBuilder
  3. # 5

Hi Ricardo,

Do you call SharedObjectUnregister after you don't need the shared object anymore (at least before you close your application?)

I use also shared objects to retrieve data. It works well. But you can't stop the database query. I think DBCancel stops only the "download" (rows fetch). So if you have a long running query the thread will run until the query has finished.

HTH,

René

Comment
  1. Ricardo Colarina
  2. Monday, 20 January 2020 20:38 PM UTC
Hi René,



Yes I do call SharedObjectUnregister and everything works well unless I close the window while the report is still processing. I also tried instead retrieving in a loop, splitting the retrieval for each PK. With this approach I was able to properly terminate the report but this doubles the processing time. I'm doing "fuzzy matching" on about billion rows, so it really takes a while to finish.



Thanks.



Ricardo
  1. Helpful
  1. René Ullrich
  2. Tuesday, 21 January 2020 06:25 AM UTC
Maybe you have a chance to kill the threads database connection from main process. In Oracle there is a "alter system kill session" or "alter system disconnect" command, in Oracle 18c also a "alter session cancel sql". Maybe there are also such methods in your DBMS.
  1. Helpful
  1. René Ullrich
  2. Tuesday, 21 January 2020 06:35 AM UTC
BTW, I implemented a CancelRequest method in the Callback object to kill the database connection. I call it if window closes.
  1. Helpful
There are no comments made yet.
Ricardo Colarina Accepted Answer Pending Moderation
  1. Monday, 20 January 2020 02:17 AM UTC
  2. PowerBuilder
  3. # 6

Hi Chris,

Yes tried that but the app freezes even before the call.  In the close event of the report window, I called a function in the callback object's instance DW variable, set in the shared object just before retrieve, which issues the DBCancel.  I tried the call in the closequery event as well, but no luck.

Thanks.

Ricardo

 

Comment
  1. Chris Pollach @Appeon
  2. Monday, 20 January 2020 02:41 AM UTC
Does the SharedObject have its own Transaction Object as an instance variable. After the DBCancel, is the TO then destroyed?
  1. Helpful
  1. Ricardo Colarina
  2. Monday, 20 January 2020 02:48 AM UTC
Hi Chris,



Thanks very much for your quick responses. And Yes to both questions.



Cheers.



Ricardo
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 20 January 2020 01:42 AM UTC
  2. PowerBuilder
  3. # 7

Hi Ricardo;

   Did you issue a DBCancel() to stop the DB thread?

Regards .... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.