Page 1 of 1

Thread, new start and deprecated resume

PostPosted: January 6th, 2013, 1:01 am
by Kambiz
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?

Re: Thread, new start and deprecated resume

PostPosted: January 8th, 2013, 9:22 am
by mathgod
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.

Re: Thread, new start and deprecated resume

PostPosted: January 8th, 2013, 5:47 pm
by Kambiz
I'm not sure whether it is okay with the older version of Delphi or not.

Re: Thread, new start and deprecated resume

PostPosted: January 9th, 2013, 1:48 pm
by arhangelsoft
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;

Re: Thread, new start and deprecated resume

PostPosted: January 13th, 2013, 11:28 am
by Kambiz
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.