?
Solved

Thread problem

Posted on 2004-09-25
8
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 1000 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 23

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 23

Expert Comment

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

F68 ;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 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