Which is the correct way to start a suspended thread in delphi 2007?

后端 未结 5 1900
南笙
南笙 2020-12-17 22:01

In delphi XE I can use the start procedure, but this method does not exist in delphi 2007.

This sample code works ok in delphi xe, using Start

MyThread         


        
5条回答
  •  粉色の甜心
    2020-12-17 22:20

    There is nothing wrong with calling Resume on a thread that was created with the CreateSuspended parameter set to true in the constructor. (Why else would there be a CreateSuspended parameter after all?)

    However, the real trouble comes in when you suspend/resume a running thread. Mainly this is due to references to open resources, such as COM objects. (For example, if you have an ADO connection object active, and a query running...it's not very ideal to suspend that thread and try to resume it later... it's obviously just not always going to work out well for you or the database connection in that scenario.)

    If you are careful with your external references, then suspending/resuming a running thread becomes much safer, except for the possible race conditions that can crop up...but those are answers for many other questions...

提交回复
热议问题