Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Won't Stop thread-2 when press cancel button(thread-3)

Status
Not open for further replies.

Karenl

MIS
Sep 25, 2003
3
US
Generating report(thread-2)with floating window allowing user to cancel report(thread-3)if user decides to. When I press cancel button(thread-3) program ends but actually the report is still generating(thread-2). I get errors of trying to read closed files from thread-2. I have tried sending, receiving and stop threads. What am I doing wrong?
 
Tough to tell w/o some better idea of your program structure. Are you doing PERFORM IN THREAD or CALL IN THREAD? You should be able to simply save the HANDLE of the thread and DESTROY it when the CANCEL button is pressed.
 
THIS IS MY CODE TO DO THE THREADS.

Code:
do-threads. 
  call thread "cancel.acu"
    handle cancel-thread
    returning into thread-return
  end-call.
  perform thread cancel-box, handle in thread-3.
  perform thread generate-report thru ex-generate-report,
    handle in thread-4.  
  wait for any thread.
ex-do-threads.

THIS IS MY CANCEL-BOX THREAD.

Code:
cancel-box. 
  perform until done
    if (thread-return = 99)
       set done to true
       move 1 to quit-report   
       stop thread thread-4
       stop thread cancel-thread
    end-if
    receive thread-return from thread-4
  end-perform.

THIS IS MY GENERATE-REPORT THREAD.

Code:
generate-report.
  perform check-route thru ex-check-route.
  perform start-repairs.
  if error1 = 1
     go to ex-generate-report.
  perform read-repairs thru ex-read-repairs.
  perform print-report thru ex-print-report.
  perform print-grand.
ex-generate-report. 
  move 99 to thread-done.    
  send thread-done to thread thread-3.
  stop thread cancel-thread.
 
Well, there are still some things I'm missing such as what is cancel.acu? Where is thread-2 referenced in your original post?

Here's a complete program sample that does approximately what you want to do:
Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  TEST.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01.
           05  STD-HANDLE                      HANDLE.
 
       SCREEN SECTION.
       01  CANCEL-SCREEN.
           05  LABEL
               "Cancel the report".
           05  PUSH-BUTTON "CANCEL"
               LINE 3 COLUMN 5
               .
       PROCEDURE DIVISION.
       0000.
           PERFORM THREAD GENERATE-REPORT
           PERFORM THREAD CANCEL-BOX
           WAIT FOR ANY THREAD
           STOP RUN
           .
       GENERATE-REPORT.
           PERFORM 100000 TIMES
               DISPLAY "TEST"
               CALL "C$SLEEP" USING 1
           END-PERFORM
           .
       CANCEL-BOX.
           DISPLAY FLOATING WINDOW
               LINES 5
               SIZE 20
               HANDLE IN STD-HANDLE
               TITLE "Cancel?"
           DISPLAY CANCEL-SCREEN UPON STD-HANDLE
           ACCEPT CANCEL-SCREEN
           .

Note that there's no need for fancy messaging or anything. Either the report finishes and the wait is satisfied, or the cancel button is pressed and the wait is satisfied. In either case, the run unit terminates.

Good luck!

Glenn
 
Glenn

Thanks for the help, but that is not exactly what I need. I am calling this Report Program from another acucobol program that I am using as a menu with a list of report options. I am calling an acucobol Report Program from the option that they chose on the Menu screen from the Menu Program.
I am wanting the Report Program to go back to the Menu Program after generating the report or when the user presses cancel. To do this I cannot use the 'Stop Run' because that will exit all programs. That is why I am using the "Exit Program' at the end of my Report Program. But when I press cancel and go back to my Menu program I get an error of 47(File not open for I-O) because the generate-report thread is still running. After pressing the cancel button the routine has closed the files and exited the Report Program with the generate-report thread still running.
Does this make sense?
Am I doing this all wrong?
Can you help me?

 
OK, I understand a bit more. Still not sure what the cancel.acu routine is doing, but ... I assume it pops a window up with a cancel button and returns 99 when it is pressed? Of course the return code is not processed since you'll fall through the WAIT FOR ANY THREAD (the loop in
CANCEL-BOX only handles the situation where the report completes).

I still think my basic model will work for you:

1. Change the STOP RUN to EXIT PROGRAM.
2. Drop your CANCEL-BOX paragraph (I think my CANCEL-BOX code is probably what cancel.acu does?)
3. Insert before the EXIT PROGRAM:

STOP THREAD CANCEL-THREAD
STOP THREAD THREAD-4
CLOSE appropriate files/cleanup

That should make sure all the threads are destroyed before you exit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top