On Mon, Nov 5, 2012 at 8:03 AM, Mark Miesfeld <miesf...@gmail.com> wrote:

> On Sun, Nov 4, 2012 at 12:13 PM, <amphitr...@ok.de> wrote:
>
>>
>>  > Your case is complicated by the fact that you are starting
>>  > another thread in the dialog object that doesn't end.
>>
>>  > Essentially what you need to do is write an ok() and a cancel()
>>  > method that over-rides the base class.  In those methods, you
>>  > will need to signal your second thread to quit, wait for it to
>>  > quit, and then invoke the superclass method to close the dialog.
>>
>> Well, when I press OK or Cancle I do not want to wait for the
>> second thread to quit, I want to force it as I don't mind what it
>> does when me, myself and I hit QUIT! How may I rise a 'halt
>> execution' or break or you-name-it to end at once?
>>
>
>
> I don't know of any way to do that.
>

There were 2 possibilities that came to mind to force the thread to quit.
 One was to raise a HALT condition, and the other was that maybe something
could be added to the ooDialog framework to force a halt using the native
C++ API.

Below is a simple framework I used to test with.  Go towards the end of
this post to get the framework program.

The idea in the program is simple, add an attribute, 'forceHalt' that is
set to true to attempt to force the thread to end.

The socketRead() method is used to simulate your thread doing a blocking
read on a socket.

NOTE that the 2 methods, .DlgUtil~halt() and .DlgUtil~terminate do NOT
exist in your version of ooDialog.  I just added them to my development
code to test if the native API would force a halt.

1.) The "raise HALT" attempt does not help.

C:\work.ooRexx\other\feature.requests>userDlg.rex
Starting blocking read on socket
Read from socket
Starting blocking read on socket
Forcing halt, using "raise HALT
    10 *-*       raise HALT
Error 4 running C:\work.ooRexx\other\feature.requests\userDlg.rex line 10:
 Program interrupted
Error 4.1:  Program interrupted with HALT condition
Read from socket
Starting blocking read on socket
Read from socket
Starting blocking read on socket
^C

The above shows that the socketRead() method continues and I need control-C
to end.

2.) Using the native C++ API Terminate() also doesn't help.  (I didn't
think it would, because it is documented as waiting for all threads to
terminate.)

C:\work.ooRexx\other\feature.requests>userDlg.rex
Starting blocking read on socket
Read from socket
Starting blocking read on socket
Forcing halt, using native API "Terminate()
Read from socket
Starting blocking read on socket
Read from socket
Starting blocking read on socket
^C

3.) Using the Halt() native API, works for this program:

C:\work.ooRexx\other\feature.requests>userDlg.rex
Starting blocking read on socket
Read from socket
Starting blocking read on socket
Forcing halt, using native API "Halt()
     8 *-*       .DlgUtil~halt()
Error 4 running C:\work.ooRexx\other\feature.requests\userDlg.rex line 8:
 Program interrupted
Error 4.1:  Program interrupted with HALT condition
    40 *-*   j = SysSleep(5)
       *-* Compiled method SEND with scope "Message"
Error 4 running C:\work.ooRexx\other\feature.requests\userDlg.rex line 40:
 Program interrupted
Error 4.1:  Program interrupted with HALT condition

C:\work.ooRexx\other\feature.requests>

But, when running the program, you can see that it actually doesn't
end immediately.  It takes a few seconds from the printing of the first
Error 4 until the second Error 4 appears and the program ends.  And, if you
increase the number of seconds used in SysSleep(), it becomes apparent that
it doesn't actually quit until it returns from the SysSleep()

My suspicion is that it would not *force* your blocking socket read to end.
 It would just end the program as soon as it returned from a read because
of data available.

Therefore, I'm back to what I originally said, I don't know of any way to
force the thread to end in your case.  The 2 methods I proposed to signal
the thread to end, would be what I would do.

Here is the framework program:

/* Simple User Dialog to test forcing a thread to quit */

  dlg = .SimpleDialog~new
  dlg~execute("SHOWTOP", IDI_DLG_OOREXX)

  if dlg~forceHalt then do
    say 'Forcing halt'
    .DlgUtil~halt()
    --.DlgUtil~terminate()
    --raise HALT
  end
  else do
    say 'Ending normally'
  end

::requires "ooDialog.cls"

::class 'SimpleDialog' subclass UserDialog

::attribute forceHalt

::method init
  forward class (super) continue

  self~forceHalt = .false
  self~create(30, 30, 257, 123, "Simple Dialog", "CENTER")

::method defineDialog

  self~createPushButton(IDOK, 142, 99, 50, 14, "DEFAULT", "Ok")
  self~createPushButton(IDCANCEL, 197, 99, 50, 14, , "Cancel")

::method initDialog
  self~start('socketRead')

::method socketRead unguarded

  do while .true
    say 'Starting blocking read on socket'
    j = SysSleep(5)
    say 'Read from socket'
  end

::method ok unguarded
  self~forceHalt = .true
  return self~ok:super


::method cancel unguarded
  self~forceHalt = .true
  return self~cancel:super

--
Mark Miesfeld
------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to