PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Problem THREAD CREATE  (Read 712 times)

Andreas Gaida

  • Little Newbie
  • *
  • Posts: 3
  • FF3 User
Problem THREAD CREATE
« on: August 06, 2012, 07:50:33 AM »

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
Code: [Select]
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

Code: [Select]
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
« Last Edit: August 06, 2012, 07:56:36 AM by Andreas Gaida »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8865
  • Windows 10
    • PlanetSquires Software
Re: Problem THREAD CREATE
« Reply #1 on: August 06, 2012, 08:58:01 AM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Robert Eaton

  • Junior Member
  • **
  • Posts: 126
Re: Problem THREAD CREATE
« Reply #2 on: August 06, 2012, 08:59:30 AM »

Paul beat me.

Code: [Select]

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
« Last Edit: August 06, 2012, 10:23:49 AM by Robert Eaton »
Logged

Andreas Gaida

  • Little Newbie
  • *
  • Posts: 3
  • FF3 User
Re: Problem THREAD CREATE
« Reply #3 on: August 06, 2012, 10:17:28 AM »

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

Michael Stefanik

  • Junior Member
  • **
  • Posts: 87
  • Windows SDK coders do it without a .NET
    • Catalyst Development
Re: Problem THREAD CREATE
« Reply #4 on: August 06, 2012, 04:24:10 PM »

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.
 
Logged
Mike Stefanik
sockettools.com

Jim Dunn

  • Junior Member
  • **
  • Posts: 111
  • Jim Dunn
Re: Problem THREAD CREATE
« Reply #5 on: August 07, 2012, 10:40:06 AM »

(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!!  : )
Logged
3.14159265358979323846264338327950
"Ok, yes... I like pie... um, I meant, pi."

Andreas Gaida

  • Little Newbie
  • *
  • Posts: 3
  • FF3 User
Re: Problem THREAD CREATE
« Reply #6 on: August 07, 2012, 01:54:12 PM »

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.
Logged