Forum > General

[SOLVED] Thread => AlwaysWaitForExecute ?

(1/4) > >>

Fred vS:
Hello.

I have some trouble with thread   :-[

After execute the thread (who is perfectly running  :)), the main application stop to work, until the thread is terminated.

When the thread is terminated, the main application re-works perfectly.

That thread.execute is the main procedure of a graphical output library.

What to do to not stop the main process ?

Here part of the code


--- Code: ---Type
   TPlugin = class(TThread)
  protected
    procedure Execute; override;
     public
  constructor Create(CreateSuspended: boolean;
      const StackSize: SizeUInt = DefaultStackSize);
end;

procedure TPlugin.execute;
  begin
  TheLibraryMainProc() ;
  end; 

--- End code ---
What is wrong ?

Fred.

Thanks.

Leledumbo:
depends on what TheLibraryMainProc does. Remember, no GUI update should be done by any thread but the main thread.

Fred vS:

--- Quote ---no GUI update should be done by any thread but the main thread.
--- End quote ---

Hum, do you mean that a other thread may not do graphical things, even if those graphical things are not related to main thread ?

So i do not understand why a TProcess can do it and a TThread cannot.

Could it be possible to run that procedure of the library via a TProcess ?

Thanks.

taazz:

--- Quote from: Fred vS on December 08, 2014, 07:46:02 pm ---
--- Quote ---no GUI update should be done by any thread but the main thread.
--- End quote ---

Hum, do you mean that a other thread may not do graphical things, even if those graphical things are not related to main thread ?

So i do not understand why a TProcess can do it and a TThread cannot.

Could it be possible to run that procedure of the library via a TProcess ?

Thanks.

--- End quote ---
Assumptions is the mother of all evil, you should know by now that you need to show us the code if you want us to find the problem.

Blestan:
Running a separate process cannot access your main form canvas - i.e updating the gui.
The main reason that only the main thread can update the gui is the event loop. Gui redraw is heavy based on messages passing - events. Lazarus apps are single event loop . Alll gui actions must be executed in the main thead via sync or something like that procedure. So if you lib is doing that you lose the advantage to execute it in a thread.

Navigation

[0] Message Index

[#] Next page

Go to full version