• Welcome to PlanetSquires Forums.
 

Problem THREAD CREATE

Started by Andreas Gaida, August 06, 2012, 07:50:33 AM

Previous topic - Next topic

Andreas Gaida

Hello
I have a problem with the start of a own Thread
i have a Textbox and a Button
and the code of the Thread writen  in FF_AppStart
and the start of the Tread in Button Click
the Program is runing but on click on Button not start the Tread
sorry for my bad english
i hope anybody can help my by the problem
THX

THREAD FUNCTION Threadx(BYVAL x AS LONG) AS LONG
LOCAL a AS DWORD
DO UNTIL a = 1000000000
a = a + 1
FF_TextBox_SetText( x, STR$(a) )
LOOP
END FUNCTION


Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
Thread Create Threadx( HWND_FORM1_TEXT1 ) To thread_id
End Function


Paul Squires

Hi,

You need to move your Threadx function out of FF_AppStart because FireFly does not parse that area for FireFly functions (eg. FF_Control_SetText). Compiling your program should result in a compile error.

I made a simple project with the Threadx function put in the Form1 code area. I made your variable thread_id as global. I pressed the command button and it worked.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Robert Eaton

#2
Paul beat me.



Global hThread as Dword
'------------
Thread Function Threadx(ByVal x As Long) As Long
Local a As Dword
Do Until a = 1000000000
a = a + 1
FF_TextBox_SetText( HWND_FORM1_FIRETEXTBOX1, Str$(a) )
Loop
End Function

'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long


Thread Create Threadx(0) To hThread        'start the new thread, argument not used
Thread Close hThread To hThread     'suggested by PowerBASIC Inc. as good practice

End Function

Andreas Gaida

THX now Works fine
I new with Firefly and i have sometimes problem to find the right place for write the code
THX

Michael Stefanik

I would just point out, what you're actually doing in that simple example is not a good idea. Updating a UI object from a worker thread can result in a deadlock situation if your thread attempts to modify a control (e.g.: a text box, etc.) while the user is interacting with that control. Generally speaking, it is preferred to use PostMessage to send a message to a window (for example, a message-only window) created by the UI thread, and have that handler perform any UI updates that are needed. If you absolutely must send a message across threads and handle an acknowledgement, then use SendMessageTimeout. That way, at least you'll avoid potential deadlocks by having the function timeout if it's not able to switch the thread context and call the message handler within a certain amount of time.
Mike Stefanik
sockettools.com

Jim Dunn

(I'm jumping in here)

Ok, so I have created a Firefly Project, with 2 buttons... if you press button 1, it just pops up a MSGBOX.

If you press button 2, it will create/run the thread.

PROBLEM:  I see that while the thread is running, I don't get the MSGBOX until I press the ALT key (or wait for the thread to finish).

HELP:  Would you be willing to show me where to put the POSTMESSAGE, and this MESSAGE-ONLY_WINDOW ??

Thx!!  : )
3.14159265358979323846264338327950
"Ok, yes... I like pie... um, I meant, pi."

Andreas Gaida

Hello
The output of the thread into the textbox is only for me a temporal think to control the threads programming after he is run good
the output command i will remove.