Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TThread.resume is deprecated in Delphi-2010 what should be used in place?

In my multithread application

I use TThread.suspend and TThread.resume

Since moving my application to Delphi 2010 I get the following warring message

[DCC Warning] xxx.pas(277): W1000 Symbol ‘Resume’ is deprecated

If Resume is deprecated what should be used in place?

EDIT 1:

I use the Resume command to start the thread - as it is Created with 'CreateSuspended' set to True and Suspend before I terminate the thread.

EDIT 2:

Here is a link the delphi 2010 manual

like image 933
Charles Faiga Avatar asked Sep 13 '09 17:09

Charles Faiga


2 Answers

Use TThread.Start instead of .Resume

--EDIT-- Start can of course only be used with Delphi 2010 (and later, presumably) to start a thread that was created suspended (where you would have used Resume before).

Using Resume/Suspend (or corresponding WinAPI functions) for thread synchronisation is NOT recommended. See the discussion here (have a look at Barry Kelly's comments).

like image 26
PhiS Avatar answered Sep 22 '22 16:09

PhiS


Charles if do you read the code of TThread class , do you find the answer.

   TThread = class      private type    .. .. ..       public        constructor Create(CreateSuspended: Boolean);        destructor Destroy; override;        procedure AfterConstruction; override;        // This function is not intended to be used for thread synchronization.        procedure Resume; deprecated;        // Use Start after creating a suspended thread.        procedure Start;        // This function is not intended to be used for thread synchronization.        procedure Suspend; deprecated;        procedure Terminate;   

See this link RAD Studio 2010: Community pulse: The day after. (Part 2)

Edit:

If you need to synchronize threads, you can use a scheme based on TMutex, TEvent and critical sections.

Bye.

like image 59
RRUZ Avatar answered Sep 20 '22 16:09

RRUZ