Author | Topic: oDlg:Configure() and Threads | |
---|---|---|
AUGE_OHR | oDlg:Configure() and Threads on Wed, 09 Jun 2010 03:08:27 +0200 hi, i have a "filled" oDlg:drawingArea:Bitmap with a Picture. now a have a Class FROM Thread placed on oDlg:drawingArea. after some Time in :execute() each Thread will ::quit() and Thread is still "alive" so i can "Re-Start" it within Class with ::start() now before "Re-Start" i change Picture of oDlg:drawingArea:Bitmap and need a oDlg:Configure() ... this raise CPU to 100 % !!! Demo an more Information see http://www.xbaseforum.de/viewtopic.php?f=32&t=4347 greetings by OHR Jimmy | |
James Loughner | Re: oDlg:Configure() and Threads on Tue, 08 Jun 2010 22:08:24 -0400 This class from thread is what exactly??? This part exists in another thread so can not see any events from the host thread. Configure would send events to all its children and this part can not see the event because it runs in a different thread. Why would you think this would work?? Jim On 06/08/2010 09:08 PM, AUGE_OHR wrote: > hi, > > i have a "filled" oDlg:drawingArea:Bitmap with a Picture. > > now a have a Class FROM Thread placed on oDlg:drawingArea. > after some Time in :execute() each Thread will ::quit() and Thread > is still "alive" so i can "Re-Start" it within Class with ::start() > > now before "Re-Start" i change Picture of oDlg:drawingArea:Bitmap > and need a oDlg:Configure() ... this raise CPU to 100 % !!! > > Demo an more Information see > http://www.xbaseforum.de/viewtopic.php?f=32&t=4347 > > greetings by OHR > Jimmy > > | |
AUGE_OHR | Re: oDlg:Configure() and Threads on Wed, 09 Jun 2010 05:41:21 +0200 hi, > Why would you think this would work?? sorry, when missunderstood : if i do NOT use oDlg:Configure() in my ChangeBack() all work fine ! i need oDlg:Configure() when change oDlg:drawingArea:Bitmap, right ? after this and "Re-Start" Thread it happend ONLY ! without oDlg:Configure() all Threads work fine with "Re-Start" so i guess my Class FROM Thread (like Help Demo) is ok. *** Code *** oBmp := XbpBitmap():New():Create() oRes := LoadResource(2000,"slotres.dll","PNG" ) oBmp:setBuffer(oRes) oBmp:transparentClr := oBmp:getDefaultBgColor() AADD(aPicture,oBmp) ... oDlg := XbpDialog():new(AppDesktop() ,SetAppWindow(),{0,0}, {600,480},, .F. ) oDlg:title := "Slot Machine" oDlg:icon := 1 oDlg:taskList := .T. oDlg:border := XBPDLG_DLGBORDER oDlg:close := { || lExit := .T. } oDlg:drawingArea:ClipChildren := .F. oDlg:drawingArea:colorBG := -255 oDlg:drawingArea:Bitmap := BMP2BMP(aPicture[ RandomInt( 1,LEN(aPicture) ) ],{600,480}) oDlg:Create() CenterControl( oDlg ) here my Class oWalze1 := SlotRoll():new() oWalze1:create(oDlg:drawingArea,, {100,40}, {128,128*3+20},PP_BRO ) oWalze1:MyEvent := xbeE_Stop1 AADD(aWalzen,oWalze1) oWalze2 := SlotRoll():new() oWalze2:create(oDlg:drawingArea,, {232,40}, {128,128*3+20},PP_BRO ) oWalze2:MyEvent := xbeE_Stop2 AADD(aWalzen,oWalze2) oWalze3 := SlotRoll():new() oWalze3:create(oDlg:drawingArea,, {364,40}, {128,128*3+20},PP_BRO ) oWalze3:MyEvent := xbeE_Stop3 AADD(aWalzen,oWalze3) oDlg:show() SetAppFocus( oDlg ) nEvent := xbe_None DO WHILE !lExit nEvent := AppEvent ( @mp1, @mp2, @oXbp,100 ) DO CASE Userdef Event, siehe SLOT.CH CASE nEvent = xbeE_Stop1 CASE nEvent = xbeE_Stop2 CASE nEvent = xbeE_Stop3 CASE nEvent = xbeE_Start IF lPicture ChangeBack(aPicture,oDlg) ENDIF FOR i := 1 TO LEN(aWalzen) SLEEP( RandomInt( 1,100 ) ) aWalzen[i]:Restart() NEXT ... FUNCTION ChangeBack(aPicture,oDlg) LOCAL oBitmap LOCAL i LOCAL aSize := oDlg:drawingArea:currentsize() LOCAL iMax := LEN(aPicture) oBitmap := BMP2BMP(aPicture[ RandomInt( 1,iMax ) ],aSize) oDlg:drawingArea:Bitmap := oBitmap here waiting Thread will "harm" by it ? oDlg:configure() RETURN oBitmap *** eof *** so why/how can a oDlg:configure() have Sideeffect on my Thread ? greetings by OHR Jimmy | |
AUGE_OHR | Re: oDlg:Configure() and Threads on Thu, 10 Jun 2010 03:21:29 +0200 hi here is my Class FROM Thread *** code *** CLASS SlotRoll FROM Thread PROTECTED: VAR terminated VAR aArray VAR workCounter VAR MyHome VAR aZahl VAR nZahlLast VAR aRoolit VAR oPbStop VAR aRes VAR oFeld1 VAR oFeld2 VAR oFeld3 VAR lStopNow VAR oStat METHOD NextZahl() METHOD DirArray() METHOD execute METHOD terminate METHOD checkTermination METHOD atStart() METHOD BroRoll() METHOD BroZufall() METHOD Schieber() METHOD RetArray() EXPORTED: METHOD init() METHOD CREATE() METHOD ReStart() VAR MyEvent VAR lTakeOff ENDCLASS METHOD SlotRoll:Init(oParent, oOwner, aPos, aSize, aPP, lVisible) ::Thread:init() ::MyEvent := NIL ::MyHome := NIL ::aZahl := {} ResourceNo gewrfelt ::aRes := {} Resource PNG ::lTakeOff := .T. ::lStopNow := .F. ::nZahlLast := 0 ::aRoolit := {1,1,1} RETURN self METHOD SlotRoll:CREATE(oParent, oOwner, aPos, aSize, aPP, lVisible) LOCAL xxx LOCAL xVar := "" LOCAL oColumn LOCAL oBitmap LOCAL oBmp LOCAL oRes LOCAL i := 0 LOCAL oClass LOCAL nRand := 0 oClass := self ::MyHome := oParent fill Array ::aArray := ::DirArray() ::oStat := XbpStatic():new( oParent,oOwner,aPos,aSize,aPP,lVisible ) ::oStat:caption := "" ::oStat:clipSiblings := .T. ::oStat:type := XBPSTATIC_TYPE_FGNDFRAME ::oStat:create() ::oFeld1 := XbpStatic():new( ::oStat, , {4,272}, {128,128}, aPP ) ::oFeld1:type := XBPSTATIC_TYPE_BITMAP ::oFeld1:caption := "" ::oFeld1:clipSiblings := .T. ::oFeld1:create() ::oFeld2 := XbpStatic():new( ::oStat, , {4,140}, {128,128}, aPP ) ::oFeld2:type := XBPSTATIC_TYPE_BITMAP ::oFeld2:caption := "" ::oFeld2:clipSiblings := .T. ::oFeld2:create() ::oFeld3 := XbpStatic():new( ::oStat, , {4, 4}, {128,128}, aPP ) ::oFeld3:type := XBPSTATIC_TYPE_BITMAP ::oFeld3:caption := "" ::oFeld3:clipSiblings := .T. ::oFeld3:create() ::BroRoll() ::BroRoll() ::BroRoll() FOR i = 0 TO 2 oBitmap := ResourceAsBmp():new():create() oBitmap:load("SLOT.EXE",1000+i,"PNG" ) oBitmap:transparentClr := oBitmap:getDefaultBgColor() AADD(::aRes, BMP2BMP(oBitmap,{36,36}) ) NEXT ::oPbStop := XbpStatic():new(oParent, ,{aPos[1]+aSize[1]/2,2},{36,36},aPbPres) ::oPbStop:type := XBPSTATIC_TYPE_BITMAP ::oPbStop:caption := ::aRes[1] ::oPbStop:lbDown := {|aPos,u1,oSelf| IF(::lStopNow,:terminate(),NIL)} ::oPbStop:create():show() RETURN self METHOD SlotRoll:ReStart() IF ::lTakeOff ::lStopNow := .F. ::terminated := .F. ::workCounter := 0 ::setInterval( ::BroZufall() ) ::start() ENDIF RETURN self METHOD SlotRoll:atStart() IF ::lTakeOff ::lStopNow := .F. ::terminated := .F. ::workCounter := 0 ::setInterval( ::BroZufall() ) ::oPbStop:Setcaption( ::aRes[3] ) ENDIF RETURN self METHOD SlotRoll:BroZufall() LOCAL nRet nRet := RandomInt( 8, 16 ) RETURN nRet METHOD SlotRoll:terminate() RETURN ( ::terminated := .T. ) METHOD SlotRoll:execute LOCAL iMax := RandomInt( 50, 60 ) IF ::lTakeOff ::lTakeOff := .F. DO WHILE ::workCounter < iMax Programmcode fr den Thread ::workCounter++ IF ::terminated EXIT ELSE SLEEP( ::BroZufall() ) ::BroRoll() ENDIF IF ((::workCounter) % 20 ) == 0 ::setInterval( NIL ) SLEEP(0) ::setInterval( ::BroZufall() ) ::oPbStop:Setcaption( ::aRes[2] ) ::lStopNow := .T. ENDIF ENDDO ::oPbStop:Setcaption( ::aRes[1] ) ::terminated := .F. ::lStopNow := .F. IF ::MyEvent <> NIL PostAppEvent(::MyEvent ,; ::aRoolit ,; ::RetArray() ,; HX_LastDialog(::MyHome) ) ENDIF ::setInterval( NIL ) ::quit() ENDIF RETURN self METHOD SlotRoll:DirArray() LOCAL aArray := {} LOCAL oBmp LOCAL oRes LOCAL i := 0 LOCAL nRand := 0 ::aZahl := {} FOR i = 1 TO MAXICON DO WHILE .T. nRand := RandomInt( 1, MAXICON ) IF ASCAN(::aZahl,{|x| x = nRand } ) > 0 ELSE AADD(::aZahl, nRand ) EXIT ENDIF ENDDO oBmp := ResourceAsBmp():new():create() oBmp:load("SLOTRES.DLL",nRand+99,"PNG" ) oBmp:transparentClr := oBmp:getDefaultBgColor() AADD(aArray,oBmp) NEXT RETURN aArray METHOD SlotRoll:NextZahl() IF ::nZahlLast <= 0 ::nZahlLast := RandomInt( 1, MAXICON ) ENDIF ::nZahlLast++ IF ::nZahlLast > MAXICON ::nZahlLast := 1 ENDIF RETURN ::nZahlLast METHOD SlotRoll:BroRoll() ::Schieber() RETURN self METHOD SlotRoll:Schieber() LOCAL xxx IF EMPTY( ::aRoolit[1] ) .OR. ; EMPTY( ::aRoolit[2] ) .OR. ; EMPTY( ::aRoolit[3] ) ::aRoolit[1] := ::NextZahl() ::aRoolit[2] := ::NextZahl() ::aRoolit[3] := ::NextZahl() ENDIF * ARemove(::aRoolit,1) * AADD(::aRoolit, ::NextZahl() ) ::aRoolit[1] := ::aRoolit[2] ::aRoolit[2] := ::aRoolit[3] ::aRoolit[3] := ::NextZahl() xxx := ::aZahl[::aRoolit[1]] ::oFeld1:SetCaption(::aArray[xxx]) xxx := ::aZahl[::aRoolit[2]] ::oFeld2:SetCaption(::aArray[xxx]) xxx := ::aZahl[::aRoolit[3]] ::oFeld3:SetCaption(::aArray[xxx]) RETURN self METHOD SlotRoll:RetArray() LOCAL aRet := {} LOCAL xxx xxx := ::aZahl[::aRoolit[1]] AADD(aRet,::aZahl[xxx]) xxx := ::aZahl[::aRoolit[2]] AADD(aRet,::aZahl[xxx]) xxx := ::aZahl[::aRoolit[3]] AADD(aRet,::aZahl[xxx]) RETURN aRet *** eof *** greetings by OHR Jimmy | |
AUGE_OHR | Re: oDlg:Configure() and Threads on Thu, 10 Jun 2010 08:18:09 +0200 hi, got it !!! to simulate BUG you need XP Manifest !!! (else transparency work not well ...) 1.) put a Picture on oDlg:drawingArea:Bitmap 2.) have Class FROM Thread on oDlg:drawingArea Class have only XbpStatic, but use { XBP_PP_BGCLR, -255 } with Resource Picture on it. 3.) do a oDlg:Configure(), no need to change something than all Class Thread will raise up CPU to 100% !!! Warning !!! IF you have this Line : > oDlg:drawingArea:colorBG := -255 greetings by OHR Jimmy |