多线程问题(30分)

  • 主题发起人 主题发起人 nottop
  • 开始时间 开始时间
N

nottop

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位,我想在form.create事件中创建一个线程,然后在以后的函数中打开、关闭,请问怎么控制。
 
先看看Delphi的帮助吧,关于TThread的
Creates an instance of a thread object.
Delphi syntax:
constructor Create(CreateSuspended: Boolean);
Description
Call Create to create a thread in an application. If CreateSuspended is False, Execute is called immediately. If CreateSuspended is True, Execute won抰 be called until after Resume is called.

Restarts the execution of a suspended thread.
Delphi syntax:
procedure Resume;
C++ syntax:
void __fastcall Resume(void);
Description
Call Resume to cause a suspended thread to start running again. Calls to Suspend can be nested;
Resume must be called the same number of times Suspend was called before the thread will resume execution.

Pauses a running thread.
Delphi syntax:
procedure Suspend;

C++ syntax:
void __fastcall Suspend(void);
Description
Call Suspend to temporarily halt execution of the thread. To resume execution after a call to Suspend, call Resume. Calls to Suspend can be nested;
Resume must be called the same number of times Suspend was called before the thread will resume execution.
 
在创建时挂起
SecondProcess := TMyThread.Create(True) //挂起
在其他过程中激活
SecondProcess.Resume;
//运行
再挂起
SecondProcess.Suspend
 
但当我定义线程为全局变量的时候,怎么老是报错!
 
多人接受答案了。
 
后退
顶部