Alaska Software Inc. - Events in a Thread()
Username: Password:
AuthorTopic: Events in a Thread()
Carlos A Beling Events in a Thread()
on Fri, 20 Sep 2019 16:53:48 -0300
Good day.
I have the method below in a class derived from Thread() for finishing 
its execution when it is typed <ESC> or <ALT+F4>:

METHOD Printform_:checkEvent()
        STATIC  lOk := .t.
        LOCAL  nEvent, mp1, mp2, oXbp

        do while .t.
           nEvent    := AppEvent(@mp1, @mp2, @oXbp, .01)
           if nEvent <> xbe_None
              oXbp:handleEvent(nEvent, mp1, mp2)
           endif
           nEvent    := LastAppEvent(@mp1, @mp2, @oXbp, ::nMyId)
           if nEvent == xbe_None
              exit
           endif
           if (nEvent == xbeP_Keyboard     .and.;
               (mp1   == xbeK_ESC     .or.;
                mp1   == xbeK_ALT_F4))
              lOk     := .f.
           endif
        enddo
RETURN lOk

When executing it, AppEvent() returns the values as the attach 
AppEvent.png and LastAppEvent() always returns the values as the attach 
LastAppEvent.png and I could not to clean the event queue.

Also I did not found in the NGs reference about this task.
Please, what do I need to do for correcting this method?

Fraternally
Beling


AppEvent.png
LastAppEvent.png
Jim LeeRe: Events in a Thread()
on Fri, 20 Sep 2019 22:14:53 +0200
hi,

you are using 4th Parameter nTimeout with AppEvent().
default 4th Parameter is 0 -> wait until a Event arrive

when set nTimout to 1 (= 1/100 Sec) and no Event arrive it will send
xbe_None (Picture 1)

---

not sure why you try LastAppEvent() to terminate your Thread.
i like Use-Def Event for my own Action

#define xbeMy_Base            0x471100001
#define xbeMy_DBLCLK          (xbeMy_Base + 1)
#define xbeMy_ESC             (xbeMy_Base + 2)

  oEsc:Activate := {|| ( PostAppEvent(xbeMy_ESC,,,oThread) }

  DO WHILE .T.
     nEvent    := AppEvent(@mp1, @mp2, @oXbp, 1)
     DO CASE
        CASE nEvent = xbe_None
            no Event
        CASE nEvent = xbeMy_ESC
           EXIT
     OTHERWISE
        there is a Event
       oXbp:handleEvent(nEvent, mp1, mp2)
  ENDDO



---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Carlos A Beling Re: Events in a Thread()
on Fri, 20 Sep 2019 18:11:26 -0300
Hello Jim:
Good afternoon.
Many thanks.
Please see:
1) if I do not use the 4th parameter the function AppEvent() enters in a 
infinity loop
2) I am using LastAppEvent() because it is used in the program source of 
the ToolTip example in the Alaska's documentation.
3) I think that only in NextAppEvent() and LastAppEvent() have the 
possbility of identify the thread.
3) the mentioned thread is triggered without operator's interaction and 
I want that it finishes when the key <ESC> or <ALT+F4> is typed

Fraternally
Beling



Em 20/09/2019 17:14, Jim Lee escreveu:
> hi,
> 
> you are using 4th Parameter nTimeout with AppEvent().
> default 4th Parameter is 0 -> wait until a Event arrive
> 
> when set nTimout to 1 (= 1/100 Sec) and no Event arrive it will send
> xbe_None (Picture 1)
> 
> ---
> 
> not sure why you try LastAppEvent() to terminate your Thread.
> i like Use-Def Event for my own Action
> 
> #define xbeMy_Base            0x471100001
> #define xbeMy_DBLCLK          (xbeMy_Base + 1)
> #define xbeMy_ESC             (xbeMy_Base + 2)
> 
>    oEsc:Activate := {|| ( PostAppEvent(xbeMy_ESC,,,oThread) }
> 
>    DO WHILE .T.
>       nEvent    := AppEvent(@mp1, @mp2, @oXbp, 1)
>       DO CASE
>          CASE nEvent = xbe_None
>              no Event
>          CASE nEvent = xbeMy_ESC
>             EXIT
>       OTHERWISE
>          there is a Event
>         oXbp:handleEvent(nEvent, mp1, mp2)
>    ENDDO
> 
> 
> 
> ---
> Diese E-Mail wurde von AVG auf Viren geprüft.
> http://www.avg.com
>
Jim LeeRe: Events in a Thread()
on Sat, 21 Sep 2019 20:05:11 +0200
hi,

ad 1.) YES you need 4th Parameter
ad 2.) no need for LastAppEvent()
ad 3.) no need for NextAppEvent()




---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Carlos A Beling Re: Events in a Thread()
on Tue, 24 Sep 2019 16:13:03 -0300
Hi Jim:
Good day.
Many thanks again.
I did the corrections that you pointed and it did not work.
I think that the thread that is running only receives event from 
Signal() or some external input like pushbuttons.

Curiosity:
In the program ..\samples\solution\Tooltip.prg it seems to have an 
mistake in:

INLINE METHOD init()
      ::nTipSensitivity := 1
      ::thread:init()
      ::producerID := ThreadID() <== may be this line must to be 
::producerId := ::threadId (variable)
      ::nLastTipTime := 0
      ::name := "Tooltip service"
    RETURN

Fraternally
Beling

Em 21/09/2019 15:05, Jim Lee escreveu:
> hi,
> 
> ad 1.) YES you need 4th Parameter
> ad 2.) no need for LastAppEvent()
> ad 3.) no need for NextAppEvent()
> 
> 
> 
> 
> ---
> Diese E-Mail wurde von AVG auf Viren geprüft.
> http://www.avg.com
>
Jim LeeRe: Events in a Thread()
on Tue, 24 Sep 2019 21:45:21 +0200
you are right that Thread can't receive Event itself ... it is the Parent
Window.

if you use a CLASS you just need a iVAR "lAbort" in Event-Loop

   o:activate := {|| oThread:lAbort := .T. }

   DO WHILE .T.
     nEvent    := AppEvent(@mp1, @mp2, @oXbp, 1)
     DO CASE
        CASE ::lAbort = .T.
           EXIT



---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Carlos A Beling Re: Events in a Thread()
on Tue, 24 Sep 2019 17:43:08 -0300
Hi Jim:
good afternoon.
Many thanks.
You are right.

Fraternally
Beling

Em 24/09/2019 16:45, Jim Lee escreveu:
> you are right that Thread can't receive Event itself ... it is the Parent
> Window.
> 
> if you use a CLASS you just need a iVAR "lAbort" in Event-Loop
> 
>     o:activate := {|| oThread:lAbort := .T. }
> 
>     DO WHILE .T.
>       nEvent    := AppEvent(@mp1, @mp2, @oXbp, 1)
>       DO CASE
>          CASE ::lAbort = .T.
>             EXIT
> 
> 
> 
> ---
> Diese E-Mail wurde von AVG auf Viren geprüft.
> http://www.avg.com
>