如果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的更多相关文章

  1. Delphi线程基础知识

    参考http://blog.chinaunix.net/uid-10535208-id-2949323.html 一.概述 Delphi提供了好几种对象以方便进行多线程编程.多线程应用程序有以下几方面 ...

  2. 多线程的基本概念和Delphi线程对象Tthread介绍

    多线程的基本概念和Delphi线程对象Tthread介绍 作者:xiaoru    WIN 98/NT/2000/XP是个多任务操作系统,也就是:一个进程可以划分为多个线程,每个线程轮流占用CPU运行 ...

  3. TMsgThread, TCommThread -- 在delphi线程中实现消息循环

    http://delphi.cjcsoft.net//viewthread.php?tid=635 在delphi线程中实现消息循环 在delphi线程中实现消息循环 Delphi的TThread类使 ...

  4. TMsgThread, TCommThread -- 在delphi线程中实现消息循环(105篇博客,好多研究消息的文章)

    在delphi线程中实现消息循环 在delphi线程中实现消息循环 Delphi的TThread类使用很方便,但是有时候我们需要在线程类中使用消息循环,delphi没有提供.   花了两天的事件研究了 ...

  5. Delphi线程定时器TThreadedTimer及用法--还有TThreadList用法可以locklist

    Delphi线程定时器 - -人生如歌- - 博客园http://www.cnblogs.com/zhengwei0113/p/4192010.html (* 自己编写的线程计时器,没有采用消息机制, ...

  6. delphi 线程教学第二节:在线程时空中操作界面(UI)

    第二节:在线程时空中操作界面(UI)   1.为什么要用 TThread ?   TThread 基于操作系统的线程函数封装,隐藏了诸多繁琐的细节. 适合于大部分情况多线程任务的实现.这个理由足够了吧 ...

  7. delphi 线程教学第一节:初识多线程

    第一节:初识多线程   1.为什么要学习多线程编程?   多线程(多个线程同时运行)编程,亦可称之为异步编程. 有了多线程,主界面才不会因为耗时代码而造成“假死“状态. 有了多线程,才能使多个任务同时 ...

  8. Java线程池ThreadPoolExecuter:execute()原理

    一.线程池执行任务的流程 如果线程池工作线程数<corePoolSize,创建新线程执行task,并不断轮训t等待队列处理task. 如果线程池工作线程数>=corePoolSize并且等 ...

  9. Java 线程池submit和execute

    submit方法: public abstract class AbstractExecutorService implements ExecutorService { protected <T ...

随机推荐

  1. mysql源码分析

    http://blog.csdn.net/u012935160/article/category/2697485

  2. [转] 剖析 epoll ET/LT 触发方式的性能差异误解(定性分析)

    http://blog.chinaunix.net/uid-17299695-id-3059078.html PS:Select和Poll都是水平触发,epoll默认也是水平触发 ET模式仅当状态发生 ...

  3. yii 载入css or js

    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/TableView.js&q ...

  4. 2015 UESTC Training for Search Algorithm & String - J - 全都是秋实大哥 【KMP】

    给出一个字符串,求每个前缀的最小循环节长度,并输出整个字符串的最小循环节.字符串长度为3*10^6 找循环节这种问题还是要用KMP对于长度为i的字符串 i%(i-f[i])==0 此时,它的最小循环节 ...

  5. 中国剩余定理模板poj1006

    #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #i ...

  6. noip 2013 华容道

    /*双向bfs (得分和单项的一样多....)70*/ #include<iostream> #include<cstdio> #include<cstring> ...

  7. canvas sprite动画 简单封装

    function SpritCtx(img, size, pos, turnTime, totalCount, ctx) { size = size || {}; pos = pos || {}; / ...

  8. 学习CSS一些事(下)

    2.浮动(float) 浮动(float)特点:1.元素会左移.右移,直到触碰到容器为止.    2.设置浮动元素,仍旧处于标准文档流. 3.当元素没有设置宽度值,而设置了浮动属性,元素的宽度随着内容 ...

  9. GridView布局及适配器优化

    1.布局样式 <GridView android:id="@+id/gridView" android:layout_width="fill_parent" ...

  10. Android中的BroadCast静态注册与动态注册

    1.静态注册 新建MyBroadcast类继承BroadcastReceiver,实现onReceive方法 /** * Author:JsonLu * DateTime:2015/9/21 16:4 ...