Delphi 线程resume 不能调用Execute
如果Resume不能唤起线程,请试试如下的函数,试试。
GetExitCodeThread(ThreadHandle,ExitCode)
来取得ExitCode,如果ExitCode=STILL_ACTIVE
表示线程还存在,对于存在的线程,则可以使用ResumeThread(ThreadHandle)来唤醒线程,如果线程仍然处于运行状态,则会返回错误具体的自己去看相关的API的返回值。
本人在实际应用中还是没能够解决上面问题,只好委曲找到另一种解决方法。
procedure TfrmDataExchangePlatformMain.ActionStartServiceExecute(
Sender: TObject);
begin
StatusBar1.Panels[1].Text := '当前操作: ' + ActionStartService.Caption;
Screen.Cursor := crHourGlass;
try
FExecfinish := True;
Timer_Service.Enabled := True;
//MyThread.Resume;
finally
Screen.Cursor := crDefault;
end;
end;
{
procedure TfrmDataExchangePlatformMain.Timer_ServiceTimer(Sender: TObject);
var
ExitCode: DWORD;
begin
//if MyThread.MyThreadExecfinish then
//MyThread.Execute;
MyThread.Resume;
GetExitCodeThread(MyThread.Handle,ExitCode);
if not MyThread.Suspended then
begin
ShowMessage('可以运行');
end;
if ExitCode=STILL_ACTIVE then
begin
ShowMessage('可以运行');
end;
end;
}
procedure TfrmDataExchangePlatformMain.Timer_ServiceTimer(Sender: TObject);
begin
MyThread := TMyThread.CreateEx(False);
MyThread.ExeTimer := Timer_Service;
MyThread.MemoLogStrings := cxMemo_Log.Lines;
MyThread.LogStrings := cxMemo_Log.Lines;;
MyThread.MyThreadExecfinish := True;
MyThread.HTTPRIOLeExp := DMConn.HTTPRIOLeExp;
MyThread.HTTPRIONC := DMConn.HTTPRIONC;
end;
{ TMyThread }
procedure TMyThread.Execute;
begin
inherited;
FreeOnTerminate := True; {这可以让线程执行完毕后随即释放}
if MyThreadExecfinish then
ExecTimer;
end;
function TMyThread.ExecTimer: Boolean;
begin
Result := False ;
FMyThreadExecfinish := False;
Screen.Cursor := crHourGlass;
CoInitialize(nil);
try
FExeTimer.Enabled := False;
TranspondClientBaseData_factory1(HTTPRIOLeExp, HTTPRIONC, LogStrings);
Sleep(1000);
TranspondPersonBaseData_factory1(HTTPRIOLeExp, HTTPRIONC, LogStrings);
Sleep(1000);
TranspondDeptBaseData_factory1(HTTPRIOLeExp, HTTPRIONC, LogStrings);
//readLogStrings;
//SaveLogFile;
finally
Result := True;
FMyThreadExecfinish := True;
CoUninitialize;
FExeTimer.Enabled := True;
Screen.Cursor := crDefault;
//Suspended := True;
end;
end;
遇到此问题的,不妨这么试试吧, 其实上面找到了原因,但是找不到解决方法, 上面应该是线程被停止了,不存在了, 但是就是不知道在哪被停止的, 因为执行两次resume的时候 exitcode和STILL_ACTIVE还是一样, 但是就是在以后就为0了, 不知道怎么回事。不找原因啦, 就用上面这个方法啦。 如果明白的,请告知小弟,嘿嘿。
Delphi 线程resume 不能调用Execute的更多相关文章
- Delphi线程基础知识
参考http://blog.chinaunix.net/uid-10535208-id-2949323.html 一.概述 Delphi提供了好几种对象以方便进行多线程编程.多线程应用程序有以下几方面 ...
- 多线程的基本概念和Delphi线程对象Tthread介绍
多线程的基本概念和Delphi线程对象Tthread介绍 作者:xiaoru WIN 98/NT/2000/XP是个多任务操作系统,也就是:一个进程可以划分为多个线程,每个线程轮流占用CPU运行 ...
- TMsgThread, TCommThread -- 在delphi线程中实现消息循环
http://delphi.cjcsoft.net//viewthread.php?tid=635 在delphi线程中实现消息循环 在delphi线程中实现消息循环 Delphi的TThread类使 ...
- TMsgThread, TCommThread -- 在delphi线程中实现消息循环(105篇博客,好多研究消息的文章)
在delphi线程中实现消息循环 在delphi线程中实现消息循环 Delphi的TThread类使用很方便,但是有时候我们需要在线程类中使用消息循环,delphi没有提供. 花了两天的事件研究了 ...
- Delphi线程定时器TThreadedTimer及用法--还有TThreadList用法可以locklist
Delphi线程定时器 - -人生如歌- - 博客园http://www.cnblogs.com/zhengwei0113/p/4192010.html (* 自己编写的线程计时器,没有采用消息机制, ...
- delphi 线程教学第二节:在线程时空中操作界面(UI)
第二节:在线程时空中操作界面(UI) 1.为什么要用 TThread ? TThread 基于操作系统的线程函数封装,隐藏了诸多繁琐的细节. 适合于大部分情况多线程任务的实现.这个理由足够了吧 ...
- delphi 线程教学第一节:初识多线程
第一节:初识多线程 1.为什么要学习多线程编程? 多线程(多个线程同时运行)编程,亦可称之为异步编程. 有了多线程,主界面才不会因为耗时代码而造成“假死“状态. 有了多线程,才能使多个任务同时 ...
- Java线程池ThreadPoolExecuter:execute()原理
一.线程池执行任务的流程 如果线程池工作线程数<corePoolSize,创建新线程执行task,并不断轮训t等待队列处理task. 如果线程池工作线程数>=corePoolSize并且等 ...
- Java 线程池submit和execute
submit方法: public abstract class AbstractExecutorService implements ExecutorService { protected <T ...
随机推荐
- [转] Python list、tuple、dict区别
from: http://www.cnblogs.com/Michael-Kong/archive/2012/07/11/2585840.html Dictionary 是 Python 的内置数据类 ...
- [转] javascript对数组的操作
javascript数组操作大全,数组方法总汇 1. shift:删除原数组第一项,并返回删除元素的值:如果数组为空则返回undefined var a = [1,2,3,4,5]; var b = ...
- codevs2034 01串2
/* 一开始认为是个水题 直接模拟 没想到只得了50分 一看数据吓niao了 模拟妥妥的TLE 实在不好优化了0.0(最快O(m)) 然后借鉴别人的 DP+神奇的输出 DP:状态:f[i][j] 前i ...
- 构建可比较的对象(IComparable)
IComparable接口 System.IComparable接口指定了一种允许一个对象可基于某些特定键值进行排序的行为. namespace System { [ComVisible(true)] ...
- Spring.Net+NHibernate+asp.net mvc + easyui
毕业4个月的入手项目..前段时间在公司一直做的维护..为了弄明白自己也就跟着写了一个,目前也正在学习:不对的或者是有更好的还请各位赐教. 在学习的过程中主要参考::http://www.cnblogs ...
- git 的记住用户名和密码和一些常用
git config --global core.autocrlf falsegit config --global color.ui truegit config --global credenti ...
- Android中px、dp、sp的区别
px: 即像素,1px代表屏幕上一个物理的像素点: px单位不被建议使用,因为同样100px的图片,在不同手机上显示的实际大小可能不同,如下图所示(图片来自android developer guid ...
- Iframe之间及iframe与父窗体之间值的传递
方法一:ScriptManager.RegisterClientScriptBlock(this,typeof(Page), "NoInformation", "wind ...
- I/O复用-select模型
IO复用: I/O复用使得程序可以同时监听多个文件描述符,这对提高程序的性能至关重要.例如TCP服务器要同时处理监听socket和连接socket,客户端要同时处理用户输入和网络连接. Linux下实 ...
- inline-block(行内区块元素)的详解和应用
说inline-block(行内区块元素)之前,先说下他另外的2个兄弟 display:inline; 内联元素,简单来说就是在同一行显示.他没有高度,给内联元素设置width和height是没效果的 ...