delphi判断线程是否正在运行
相关资料:
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判断线程是否正在运行的更多相关文章
- delphi判断线程状态函数(使用GetExitCodeThread API函数去判断线程的句柄)
//判断线程是否释放//返回值:0-已释放:1-正在运行:2-已终止但未释放://3-未建立或不存在 function CheckThreadFreed(aThread: TThread): Byte ...
- Delphi中线程类TThread实现多线程编程1---构造、析构……
参考:http://www.cnblogs.com/rogee/archive/2010/09/20/1832053.html Delphi中有一个线程类TThread是用来实现多线程编程的,这个绝大 ...
- 转发 Delphi中线程类TThread 实现多线程编程
Delphi中有一个线程类TThread是用来实现多线程编程的,这个绝大多数Delphi书藉都有说到,但基本上都是对TThread类的几个成员作一简单介绍,再说明一下Execute的实现和Synchr ...
- 转:学习笔记: Delphi之线程类TThread
学习笔记: Delphi之线程类TThread - 5207 - 博客园http://www.cnblogs.com/5207/p/4426074.html 新的公司接手的第一份工作就是一个多线程计算 ...
- 学习笔记: Delphi之线程类TThread
新的公司接手的第一份工作就是一个多线程计算的小系统.也幸亏最近对线程有了一些学习,这次一接手就起到了作用.但是在实际的开发过程中还是发现了许多的问题,比如挂起与终止的概念都没有弄明白,导致浪费许多的时 ...
- 一个线程加一运算,一个线程做减一运算,多个线程同时交替运行--synchronized
使用synchronized package com.pb.thread.demo5; /**使用synchronized * 一个线程加一运算,一个线程做减法运算,多个线程同时交替运行 * * @a ...
- Delphi ThreadPool 线程池(Delphi2009以上版本适用)
http://blog.sina.com.cn/s/blog_6250a9df0101kref.html 在网上查找Delphi线程池,结果发现寥寥无几. 看了半天源代码,弄得一头雾水,觉得不容易理解 ...
- 在C#中如何判断线程当前所处的状态
在C#中,线程对象Thread使用ThreadState属性指示线程状态,它是带Flags特性的枚举类型对象. ThreadState 为线程定义了一组所有可能的执行状态.一旦线程被创建,它就至少 ...
- C#中如何判断线程当前所处的状态
转自原文 在C#中如何判断线程当前所处的状态 在C#中,线程对象Thread使用ThreadState属性指示线程状态,它是带Flags特性的枚举类型对象. ThreadState 为线程定义了 ...
随机推荐
- ROS学习(十三)—— 编写简单的Service和Client (C++)
一.编写Service节点 1.节点功能: 我们将创建一个简单的service节点("add_two_ints_server"),该节点将接收到两个整形数字,并返回它们的和. 2. ...
- HDU 3032 Nim or not Nim? (sg函数)
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- POJ 1862 Stripies (哈夫曼树)
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10263 Accepted: 4971 Descrip ...
- mac使用phpize进行安装的时候碰到的问题
问题: grep: /usr/include/php/main/php.h: No such file or directory grep: /usr/include/php/Zend/zend_mo ...
- Java and C# Comparison
原文:http://www.harding.edu/fmccown/java_csharp_comparison.html Java Program Structure C# package hell ...
- HSSFWorkbook 与 XSSFWorkbook
刚开始使用new HSSFWorkbook(new FileInputStream(excelFile))来读取Workbook,对Excel2003以前(包括2003)的版本没有问题,但读取Exce ...
- java 发送post请求参数中含有+会转化为空格的问题
如题 原因分析:参数在传递过程中经历的几次编码和解码标准不同,导致加号.空格等字符的错误. 解决方案:将post请求的参数中 ,含有+号的,统统采用%2B 去替换,这是URL的协议问题.
- 数字的可视化:python画图之散点图sactter函数详解
最近开始学习python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...
- ios标准开发者账号 ios企业开发者账号的区别总结
ios标准开发者账号 ios企业开发者账号的区别总结 ios标准开发者项目 1.ios标准开发者项目账号可以发布到app store 2.ios标准开发者项目分为两种:①个人开发者②公司/机构开发 ...
- Java – How to convert a primitive Array to List
Java – How to convert a primitive Array to ListCode snippets to convert a primitive array int[] to a ...