Thread, new start and deprecated resume

Please discuss general Delphi programming topics here.

Thread, new start and deprecated resume

Postby Kambiz » January 6th, 2013, 1:01 am

As you already may know, from Delphi 2010 Resume and Suspend methods of TThread class are deprecated. In other hand, a thread that is created as suspended needs a way to be resumed and because of that the new Start method is introduced.

However, when I call Start method on a thread that is created as suspended, an exception complains that the thread is not suspended and then cannot be started.

Sample code
Code: Select all
constructor MyThread.create;
begin
  inherited Create(true);
  FreeOnTerminate := true;
  Start; // the exception occurs here. if I use resume, no exception occurs, but deprecation message.
end;


Could somebody please help me to get out of this confusion?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Thread, new start and deprecated resume

Postby mathgod » January 8th, 2013, 9:22 am

Can you unset the suspend flag so that the thread is created as not suspended? If this is possible, then calling Start would not be necessary.
User avatar
mathgod
Junior Member
Junior Member
 
Posts: 35
Joined: December 15th, 2007, 4:36 pm
Location: Middle of New Mexico, USA

Re: Thread, new start and deprecated resume

Postby Kambiz » January 8th, 2013, 5:47 pm

I'm not sure whether it is okay with the older version of Delphi or not.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Thread, new start and deprecated resume

Postby arhangelsoft » January 9th, 2013, 1:48 pm

Could somebody please help me to get out of this confusion?

Never don't run thread from it's self. This is made for security purposes for safely synchronization between thread and another threads.
If you will be do this, you can make situations when code in synchronization block randomly may wait event which will be never happen.
It's may make some big problems.

I write as code as your code many times:
Code: Select all
constructor TMYThread.Create;
begin
 inherited Create(True);
 FreeOnTerminate:=True;
{Some filds creation and etc. EXCEPTs start thread}
end;


In class owner of TmyThread, I'm use TmyThread.Start;
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: Thread, new start and deprecated resume

Postby Kambiz » January 13th, 2013, 11:28 am

Using Thread without a wrapper has no problem. It's years I'm doing this and you can see the examples in my codes here.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron