线程挂起后再起用的问题 为什么界面线程不能向自定义线程发送消息 ( 积分: 50 )

  • 主题发起人 主题发起人 xgwzw
  • 开始时间 开始时间
X

xgwzw

Unregistered / Unconfirmed
GUEST, unregistred user!
如果大家感兴趣 也可以给我讨论指导一点Socket的模式编程,协议编程的方面的问题
另外请问大家一个画流程图的软件
生成*.emf文件的
 
如果大家感兴趣 也可以给我讨论指导一点Socket的模式编程,协议编程的方面的问题
另外请问大家一个画流程图的软件
生成*.emf文件的
 
一个线程的Execute 执行完后,怎么再一次的Resume呢
请网络高手指点
 
while turn do
Begin
....
suspend
end

由主线程来传入数据,传入完成后对线程resume就可以了
 
怎么我测试不行啊
 
unit Thread;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
m:integer;

implementation

{$R *.dfm}
var
ThreadIdHandle:THandle;



function ThreadProc(Info:Pointer):integer;stdcall;
var

S:String;
begin
inc(m);
//Form1.Invalidate;
Form1.Canvas.TextOut(10,10,Inttostr(m));
Sleep(5000);
SuspendThread(ThreadIdHandle);

end;


procedure TForm1.Button1Click(Sender: TObject);
var
ThreadId: DWORD;
ExitCode:DWORD;
begin
ThreadIdHandle:=CreateThread(nil,0,@ThreadProc,nil,CREATE_SUSPENDED,ThreadId);
ResumeThread(ThreadIdHandle);
sleep(1000);
end;



procedure TForm1.Button3Click(Sender: TObject);
begin

ResumeThread(ThreadIdHandle);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
m:=0;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
SuspendThread(ThreadIdHandle);
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
ExitCode: DWORD; // holds the thread exit code
begin
{retrieve and display the thread's exit code}
GetExitCodeThread(ThreadIdHandle, ExitCode);
end;

end.
//按button3 后再按button4
//怎么m的值怎么没有改变
 
unit Thread;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
m:integer;

implementation

{$R *.dfm}
var
ThreadIdHandle:THandle;



function ThreadProc(Info:Pointer):integer;stdcall;
var

S:String;
begin
Inc(Pinteger(Info)^);
//Form1.Invalidate;
Form1.Canvas.TextOut(10,10,Inttostr(m));
Sleep(5000);
SuspendThread(ThreadIdHandle);


end;


procedure TForm1.Button1Click(Sender: TObject);
var
ThreadId: DWORD;
ExitCode:DWORD;
begin
ThreadIdHandle:=CreateThread(nil,0,@ThreadProc,@m,CREATE_SUSPENDED,ThreadId);
ResumeThread(ThreadIdHandle);
sleep(1000);
end;



procedure TForm1.Button3Click(Sender: TObject);
begin

ResumeThread(ThreadIdHandle);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
m:=0;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
SuspendThread(ThreadIdHandle);
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
ExitCode: DWORD; // holds the thread exit code
begin
{retrieve and display the thread's exit code}
GetExitCodeThread(ThreadIdHandle, ExitCode);
end;

end.
//传入数据也不行 不知是不是有问题
 
生成*.emf文件
http://www.eclipse.org/emf/
 
MS visio可以生成*.emf文件的流程图
 
unit Unitxx;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Const WM_MyMSG1=WM_USER+1002;
WM_MyMSG=WM_USER+1003;
type
my = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure onmymsg1(var message:TMessage);
end;


type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure onmymsg(var message:TMessage);message WM_MyMSG;

public
{ Public declarations }
end;

var
Form1: TForm1;

var
m1:dword;



implementation

{$R *.dfm}

procedure TForm1.onmymsg(var message: TMessage);
begin
showmessage('123');
end;

procedure TForm1.Button1Click(Sender: TObject);
var m:my;
begin

m:=my.Create(false);
m.FreeOnTerminate:=true;
sendmessage(m1,WM_MyMSG1,0,0);
end;

{ my }

procedure my.Execute;
begin
inherited;
m1:=GetCurrentThread;
sendmessage(form1.Handle,WM_MyMSG,0,0);
//sendmessage(m1,WM_MyMSG1,0,0);
end;

procedure my.onmymsg1(var message: TMessage);
begin
showmessage('1AAA');
form1.Canvas.TextOut(10,20,'qwertyuiop');
end;

end.


//为什么界面线程不能向自定义线程发送消息 还是我的想法是错误的
 
怎么没有大侠帮忙
 
都挂起来了,还怎么接收消息?
 
to datm
请看下面的时间写的也就是我贴的第三个代码 没有挂起啊
来自:xgwzw, 时间:2005-7-17 18:53:42, ID:3137223 | 编辑
前面2个代码是关于挂起再重用的问题
 
to datm 我的第一个代码中
//按button3 后再按button4?
//怎么m的值怎么没有改变?
线程挂起后难道不能被重用?
 
to datm 我的第一个代码中
线程难道不能被重用?
 
唉。主窗体往线程发消息不是这样发的,如果是线程往主窗体倒是可以这样发。主窗体发到
线程需要使用PostThreadMessage的。另外,,,不说了,反正需要多看些线程的应用代码。
 
多研究研究吧
 
to 小雨哥
改怎么发呢
 
如果新的线程建立了窗口则可以SendMessage/PostMessage来发送, 否则的话可以用PostThreadMessage来发送, 这两种情况都需要线程作消息循环, 注意不同线程间的SendMessage是同步式的, 可能导致死锁, 可改用SendMessageTimeout等函数
 
to 刘麻子
谢谢 线程池的用法呢?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部