Solved

Thread problem

Posted on 2004-09-25
8
356 Views
Last Modified: 2010-04-06
When I try to set:

Priority := tpNormal ;

get next error message:

"Thread error: The handle is invalid (6)"

constructor TGNThread.Create( AnimateMe : TgnClass );
begin
 Animated                 := AnimateMe;
 Priority                    := tpNormal     ; // here is my problem. If delete it all work fine !?!?!?
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;
 inherited Create ( False );
end;

0
Comment
Question by:ginsonic
  • 4
  • 2
  • 2
8 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 250 total points
ID: 12150412


constructor TGNThread.Create( AnimateMe : TgnClass );
begin
inherited Create ( true);
 Animated                 := AnimateMe;
 Priority                    := tpNormal     ; // here is my problem. If delete it all work fine !?!?!?
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;
 suspended := false;
end;
0
 
LVL 22

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 250 total points
ID: 12150453
vadim_ti is right....(he deserves the points)

Now just to explane it you can change the default Priority just when the Thread is already created otherwise the error is raised as there's no handle for the Thread, tyhat means that the System try to execute scheduled a non-handled Thread....

So you can also write your constructor as

constructor TGNThread.Create( AnimateMe : TgnClass );
begin
   Animated                 := AnimateMe;
   OnTerminate           := Animated.Fine;
   FreeOnTerminate     := True; //'til here the Thread handle isn't needed as these are just Object properties
   inherited Create ( true);
   Priority                    := tpNormal; //but this needs the Thread handle in process
   Resume; //Now let's resume it
end;

0
 
LVL 9

Author Comment

by:ginsonic
ID: 12153480
I split the points beacause the real solution was to call firat inherited Create(True);
Don't need to suspend or resume my thread. Just:

 Animated                 := AnimateMe;
 Priority                    := tpNormal     ;
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;
 suspended := false;

 What was interesting is that an old compiled exe what use inherited after ( wrongh way ) run perfect !?!? The new compiled return the error!?!?!?

Thanks for help!
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 9

Author Comment

by:ginsonic
ID: 12153483
Sorry , I wish to say:

 inherited Create ( true);
 Animated                 := AnimateMe;
 Priority                    := tpNormal     ;
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;

Copy problem :)
0
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12153573
with your contructor without

suspended := false

thread will not run (execute). you will successfully create it, but it will in suspended state

inherited Create(true)

will create it in suspended,
.Execute method will never called

so you need
suspended := false or calling Resume

to resume thread
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12155194
Look like resume solve all problems. Suspended make my VCL to not work for all my actions.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12155196
Thanks again for support!
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12155393
:)) That's why i've used resume in my example :)

F68 ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question