START new Window does not show until the end

Hello,

I have procedure to process some data, and in the other procedure I have defined progress window.

Code is like this:

DoSomething     PROCEDURE()
CODE
    START(ProgressWindow)
    ! Data processing

But ProgressWindow is opened after DoSomething is over. Why is that? I have added MESSAGE() in Init PROCEDURE() of the PreogressWindow, and the message box is opened at the begining. But window shows only after DoSomething is over

What am I missing or am I doing it wrong?

You can use RESUME(START(ProgressWindow)) to start the thread immediately.
You will need some mechanism to send progress information to the progress window thread.

2 Likes

When 6 came out with the new threading model a new help topic Launching a thread - behind the scenes documented a STARTed new thread does not really run (its suspended) until the STARTer thread gets back to its Accept loop, or RESUME(new). Here’s the help, its worth knowing this …


With the advent of two new language statements supporting thread management in Clarion 6 (SUSPEND and RESUME), it is important to understand that there are a few things that are initialized and executed behind the scenes by the runtime library each time a thread is STARTed.

Here is the sequence of actions performed by the launching thread and the runtime library(RTL) each time a thread is STARTed:

  1. Launching Thread executes START(ThreadProc)
  2. RTL creates the physical thread in suspended state.
  3. RTL resumes the launched thread created in step 2.
  4. RTL sets an internal semaphore to a nonsignaled state.
  5. Launching Thread waits for the semaphore from the RTL.
  6. RTL creates instances of threaded variables and calls initialization routines for them.
  7. RTL sets the semaphore to signaled state.
  8. RTL suspends the launched thread creates in step 2.
  9. Launching Thread continues program execution.

The launching thread will continue until it encounters the ACCEPT statement. Upon execution of the ACCEPT statement:

  1. RTL resumes the launched thread.
  2. RTL calls the entry point of the ThreadProc.

Therefore, a launched thread will remain suspended until the next call to ACCEPT from the launching thread. Only initialization and constructors for threaded variables are executed.

The use of RESUME with the START statement immediately executes Step 10 above without waiting for the call to ACCEPT. In other words, use of RESUME with START does not depend on the ACCEPT statement for resuming thread execution. This allows a new thread to be started from windowless threads.

The same can be said by using the SUSPEND statement immediately after START, e.g., SUSPEND immediately stops thread execution and does not wait for the ACCEPT loop.

2 Likes

Thank you all for help. It works with RESUME.

And is it possible to call ACCEPT on demand? I have tried with POST(EVENT:Accepted) but it does not work. Is it some other ACCEPT or is it called some other way?

You can just start an ACCEPT loop. You can even have a prior one active so they are basically nested. You need a way to assure it gets an Event. I usually turn on a Timer, you could Post() Event:Notify or Event:User.

0{PROP:Timer}=1  !assure we get an event
ACCEPT
    CASE EVENT()
    OF EVENT:Timer                      
       0{PROP:Timer}=0
       BREAK
    !OF  other events?
    END
END
1 Like