how to react when calling from hb_thread
Posted: Tue Feb 04, 2020 10:21 am
hi,
i try to implement USB_Detect() but have some Problem
USB_Detect() get Windows Event
Wait4Action() is running in hb_thread and wait for "Action"
Problem :
a.) it work on Win_1.HANDLE but on Form are many Controls so if Mouse Cursor is not on Win_1 -> nothing happens
b.) as i´m in hb_thread i can not call Controls this Way in FillCombo()
so what do i miss in harbour / HMG Thread Concept
please give me a hint.
p.s. have a Version with Mutex but same Problem
i try to implement USB_Detect() but have some Problem
Code: Select all
aThread[ 1 ] := hb_threadStart(HB_THREAD_INHERIT_PUBLIC , @Wait4Action() )
aThread[ 2 ] := hb_threadStart(HB_THREAD_INHERIT_PUBLIC , @DoNothing() )
CREATE EVENT PROCNAME USB_Detect() HWND Win_1.HANDLE STOREINDEX nIndex
Code: Select all
FUNCTION USB_Detect()
LOCAL nHWnd := EventHWND()
LOCAL nMsg := EventMSG()
LOCAL nWParam := EventWPARAM()
LOCAL nLParam := EventLPARAM()
DO CASE
CASE nMsg == WM_DEVICECHANGE
DO CASE
CASE nWParam == DBT_DEVICEARRIVAL
lPublic := .T.
CASE nWParam == DBT_DEVICEREMOVECOMPLETE
lPublic := .T.
End CASE
End Case
RETURN cDevice
Code: Select all
STATIC FUNCTION Wait4Action()
DO While !lExit
IF lPublic = .T.
lPublic = .F.
cAction := aAction[1]
cDevice := aAction[2]
nInfo := aAction[3]
IF !EMPTY(cAction) .AND. !EMPTY(cDevice)
cText := cAction + " " + cDevice + CRLF
Msginfo(cText,STR(nInfo))
ENDIF
aAction := { "", "","" }
FillCombo(.T.) // this is the Way to crash App
ENDIF
EndDo
RETURN nil
a.) it work on Win_1.HANDLE but on Form are many Controls so if Mouse Cursor is not on Win_1 -> nothing happens
b.) as i´m in hb_thread i can not call Controls this Way in FillCombo()
Code: Select all
Domethod( "WinLeft" , "ComboLeft" , "DeleteAllItems" )
include Main Win_1Control: ComboLeft Of WinLeft Not defined. Program Terminated
Called from DOMETHOD(9090)
Called from FILLCOMBO(872)
Called from WAIT4ACTION(812)
Code: Select all
Domethod( "Win_1", "WinLeft" , "ComboLeft" , "DeleteAllItems" )
Wait4Action is running in Thread but i have no Access to Form Win_1 and it´s ControlsControl: WinLeft Of Win_1 Not defined. Program Terminated
Called from DOMETHOD(9240)
Called from FILLCOMBO(872)
Called from WAIT4ACTION(812)
so what do i miss in harbour / HMG Thread Concept
please give me a hint.
p.s. have a Version with Mutex but same Problem