相关资料:
http://www.delphitop.com/html/xiancheng/376.html

 unit Unit1;

 interface

 uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type
TMyThread = class(TThread)//自定义的线程
protected
procedure Execute; override;
end; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1;
mytd: TMyThread;//线程对像
implementation {$R *.dfm} //返回值:0-已释放;1-正在运行;2-已终止但未释放;3-未建立或不存在
function CheckThreadFreed(aThread: TThread): Byte;
var
I: DWord;
IsQuit: Boolean;
begin
if Assigned(aThread) then
begin
IsQuit := GetExitCodeThread(aThread.Handle, I);
if IsQuit then //If the function succeeds, the return value is nonzero.
//If the function fails, the return value is zero.
begin
if I = STILL_ACTIVE then //If the specified thread has not terminated,
//the termination status returned is STILL_ACTIVE.
Result :=
else
Result := ; //aThread未Free,因为Tthread.Destroy中有执行语句
end
else
Result := ; //可以用GetLastError取得错误代码
end
else
Result := ;
end; procedure TMyThread.Execute;
var
I: Integer;
begin
for I := to do
begin
Form1.Canvas.Lock;
Form1.Canvas.TextOut(, , IntToStr(I));
Form1.Canvas.Unlock;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckThreadFreed(mytd)<> then //判断线程是否存在
begin
mytd := TMyThread.Create(True);
mytd.FreeOnTerminate := True;
mytd.Resume;
end;
end; end.

delphi判断线程是否正在运行的更多相关文章

  1. delphi判断线程状态函数(使用GetExitCodeThread API函数去判断线程的句柄)

    //判断线程是否释放//返回值:0-已释放:1-正在运行:2-已终止但未释放://3-未建立或不存在 function CheckThreadFreed(aThread: TThread): Byte ...

  2. Delphi中线程类TThread实现多线程编程1---构造、析构……

    参考:http://www.cnblogs.com/rogee/archive/2010/09/20/1832053.html Delphi中有一个线程类TThread是用来实现多线程编程的,这个绝大 ...

  3. 转发 Delphi中线程类TThread 实现多线程编程

    Delphi中有一个线程类TThread是用来实现多线程编程的,这个绝大多数Delphi书藉都有说到,但基本上都是对TThread类的几个成员作一简单介绍,再说明一下Execute的实现和Synchr ...

  4. 转:学习笔记: Delphi之线程类TThread

    学习笔记: Delphi之线程类TThread - 5207 - 博客园http://www.cnblogs.com/5207/p/4426074.html 新的公司接手的第一份工作就是一个多线程计算 ...

  5. 学习笔记: Delphi之线程类TThread

    新的公司接手的第一份工作就是一个多线程计算的小系统.也幸亏最近对线程有了一些学习,这次一接手就起到了作用.但是在实际的开发过程中还是发现了许多的问题,比如挂起与终止的概念都没有弄明白,导致浪费许多的时 ...

  6. 一个线程加一运算,一个线程做减一运算,多个线程同时交替运行--synchronized

    使用synchronized package com.pb.thread.demo5; /**使用synchronized * 一个线程加一运算,一个线程做减法运算,多个线程同时交替运行 * * @a ...

  7. Delphi ThreadPool 线程池(Delphi2009以上版本适用)

    http://blog.sina.com.cn/s/blog_6250a9df0101kref.html 在网上查找Delphi线程池,结果发现寥寥无几. 看了半天源代码,弄得一头雾水,觉得不容易理解 ...

  8. 在C#中如何判断线程当前所处的状态

    在C#中,线程对象Thread使用ThreadState属性指示线程状态,它是带Flags特性的枚举类型对象.   ThreadState 为线程定义了一组所有可能的执行状态.一旦线程被创建,它就至少 ...

  9. C#中如何判断线程当前所处的状态

    转自原文 在C#中如何判断线程当前所处的状态 在C#中,线程对象Thread使用ThreadState属性指示线程状态,它是带Flags特性的枚举类型对象.    ThreadState 为线程定义了 ...

随机推荐

  1. 【转】25.windbg-!gle、g(错误码、g系列)

    !gle !gle 扩展显示当前线程的最后一个错误码.这个太好记了,getlasterror取首字母: <span style=:> !gle LastErrorValue: (Win32 ...

  2. TripleDES之C#和PHP之间加密解密

    在C#常用加密解密一文中,介绍了几个加密解密方法,其中有个如何使用对称加密算法DES,此次说下DES的升级版,TripleDES. DES和TripleDES之间的关系可以参考下面的博文. 对称加密D ...

  3. 根据友盟统计错误分析线上的崩溃-b

    登陆友盟官网找到友盟统计,找到你iOS平台下你所属的APP(图1) 图1 点击进去会出现当日错误列表,选择你发生错误的日期(图2) 图2 我们可以看到,这一天中出现了两个错误,每个错误出现在不同的时间 ...

  4. android studio 如何让包名展开

    通常我们新建一个包名的时候,会发现他们连在一起,根本无法在创建一个同级的包 工具/原料   电脑,android studio 方法/步骤     1,我们先在包名下建一个包,变成了这样,根本无法在同 ...

  5. 使用grep恢复被删文件内容

    在Unix/Linux下,最危险的命令恐怕就属rm命令了,每次在root下使用这个命令的时候,我都要盯着命令行看上几分钟才敢把回车敲下去.以前,看到同事在脚本中使用rm命令 —— rm {$App_D ...

  6. [转] spring的普通类中如何取session和request对像

    在使用spring时,经常需要在普通类中获取session,request等对像.比如一些AOP拦截器类,在有使用struts2时,因为struts2有一个接口使用org.apache.struts2 ...

  7. Java 8 – StringJoiner example

    In this article, we will show you a few StringJoiner examples to join String. 1. StringJoiner1.1 Joi ...

  8. VB通用数据库操作方法

    1.VB通用数据操作方法. 2.通用数据库查询方法. 3.通用数据库操作方法. 'ERP查询数据库 Public Function YZQuery(sqls As String, msgstring ...

  9. 增加nginx虚拟主机配置文件(conf.d)

    有时候我们按照了nginx后发现配置文件只有一个,/etc/nginx/nginx.conf 所有的配置包括虚拟目录也在此文件中配置, 这样当虚拟主机多了管理就有些不方便了, 这是需要我们把配置文件拆 ...

  10. mysql分享一:运维角度浅谈MySQL数据库优化

    转于:http://lizhenliang.blog.51cto.com/7876557/1657465 1.数据库表设计要合理避免慢查询.低效的查询语句.没有适当建立索引.数据库堵塞(死锁)等 2. ...