高分跪求pb多线程源代码!!

chen_pb 2004-12-16 10:16:09
只要能够实现多线程计数之类的东西,不需要太多的功能!

我的信箱:chen_pb@163.com

谢谢!!万分感谢!!!
...全文
372 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hygougou 2004-12-16
  • 打赏
  • 举报
回复
PB65自己所带的例程中有一个这个东东的,你可以看一下。
(位置:C:\Program Files\Sybase\PB6\examples\distrib\srvrpush
在pb7中也可以实现多线程。
http://www.sybase.com.cn/cn/content/developer/exp_kfzly_jqhz_PB_dialog_center_show.htm
TGWall 2004-12-16
  • 打赏
  • 举报
回复
版主果然厉害
WorldMobile 2004-12-16
  • 打赏
  • 举报
回复
以上是多线程的源代码,创建这四个对象后,在你的程序中用
open(w_multithread)
把w_multithread打开,点击MultiThreaded的按钮即可看到多线程的例子
WorldMobile 2004-12-16
  • 打赏
  • 举报
回复
4.w_multithread

forward
global type w_multithread from Window
end type
type st_5 from statictext within w_multithread
end type
type st_time from statictext within w_multithread
end type
type st_4 from statictext within w_multithread
end type
type st_3 from statictext within w_multithread
end type
type cb_1 from commandbutton within w_multithread
end type
type cb_2 from commandbutton within w_multithread
end type
type st_2 from statictext within w_multithread
end type
type st_1 from statictext within w_multithread
end type
end forward

global type w_multithread from Window
int X=247
int Y=224
int Width=1797
int Height=392
boolean TitleBar=true
string Title="Multi-Threading with PowerBuilder"
long BackColor=77652192
boolean ControlMenu=true
boolean MinBox=true
boolean MaxBox=true
boolean Resizable=true
event type long ue_thread1 ( )
event type long ue_thread2 ( )
st_5 st_5
st_time st_time
st_4 st_4
st_3 st_3
cb_1 cb_1
cb_2 cb_2
st_2 st_2
st_1 st_1
end type
global w_multithread w_multithread

type variables
nv_Test inv_Test1
nv_Test inv_Test2
nv_arg1 inv_arg1
nv_arg2 inv_arg2



end variables

event ue_thread1;st_1.text = string(inv_test1.of_GetCount())
return 1

end event

event ue_thread2;st_2.text = string(inv_test2.of_GetCount())
return 1

end event

on w_multithread.create
this.st_5=create st_5
this.st_time=create st_time
this.st_4=create st_4
this.st_3=create st_3
this.cb_1=create cb_1
this.cb_2=create cb_2
this.st_2=create st_2
this.st_1=create st_1
this.Control[]={this.st_5,&
this.st_time,&
this.st_4,&
this.st_3,&
this.cb_1,&
this.cb_2,&
this.st_2,&
this.st_1}
end on

on w_multithread.destroy
destroy(this.st_5)
destroy(this.st_time)
destroy(this.st_4)
destroy(this.st_3)
destroy(this.cb_1)
destroy(this.cb_2)
destroy(this.st_2)
destroy(this.st_1)
end on

event open;inv_arg1 = create nv_arg1
inv_arg2 = create nv_arg2

inv_arg1.of_setParent(this)
inv_arg2.of_setParent(this)

timer(1,this)
end event

event closequery;SharedObjectUnRegister('object1')
SharedObjectUnRegister('object2')

destroy inv_arg1
destroy inv_arg2


end event

event timer;st_5.text = string(now())
end event

type st_5 from statictext within w_multithread
int X=987
int Y=160
int Width=311
int Height=80
boolean Enabled=false
boolean Border=true
BorderStyle BorderStyle=StyleLowered!
string Text="00:00:00"
Alignment Alignment=Center!
boolean FocusRectangle=false
long TextColor=8388608
long BackColor=67108864
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type st_time from statictext within w_multithread
int X=987
int Y=48
int Width=302
int Height=76
boolean Enabled=false
boolean Border=true
BorderStyle BorderStyle=StyleRaised!
string Text="Time"
Alignment Alignment=Center!
boolean FocusRectangle=false
long TextColor=16711680
long BackColor=67108864
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type st_4 from statictext within w_multithread
int X=1317
int Y=48
int Width=384
int Height=76
boolean Enabled=false
boolean Border=true
BorderStyle BorderStyle=StyleRaised!
string Text="Count proces 2"
Alignment Alignment=Center!
boolean FocusRectangle=false
long TextColor=16711680
long BackColor=67108864
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type st_3 from statictext within w_multithread
int X=585
int Y=48
int Width=384
int Height=76
boolean Enabled=false
boolean Border=true
BorderStyle BorderStyle=StyleRaised!
string Text="Count proces 1"
Alignment Alignment=Center!
boolean FocusRectangle=false
long TextColor=16711680
long BackColor=67108864
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type cb_1 from commandbutton within w_multithread
int X=37
int Y=32
int Width=421
int Height=96
int TabOrder=20
string Text="SingleThreaded"
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

event clicked;/* remove the thread object from memory */

SharedObjectUnRegister('object1')
SharedObjectUnRegister('object2')

if IsValid(inv_Test1) then
destroy inv_Test1
end if
if IsValid(inv_Test2) then
destroy inv_Test2
end if

/* create objects */
inv_test1 = create nv_test
inv_test2 = create nv_test

inv_Test1.of_SetParent(inv_arg1)
inv_Test2.of_SetParent(inv_arg2)

/* start the threads. You'll noticed that first thread1 is executed */
/* when finished, thread2 is executed */

inv_Test1.Post of_Start()
inv_Test2.Post of_Start()



end event

type cb_2 from commandbutton within w_multithread
int X=37
int Y=160
int Width=421
int Height=96
int TabOrder=10
string Text="MultiThreaded"
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

event clicked;if IsValid(inv_Test1) then
destroy inv_Test1
end if
if IsValid(inv_Test2) then
destroy inv_Test2
end if

/* create runtime environments for each thread */

SharedObjectRegister('nv_test','object1')
SharedObjectRegister('nv_test','object2')
SharedObjectGet('object1',inv_Test1)
SharedObjectGet('object2',inv_Test2)

inv_Test1.of_SetParent(inv_arg1)
inv_Test2.of_SetParent(inv_arg2)

/* start proces 1 and 2 and use server push (post) */

inv_Test1.POST of_Start()
inv_Test2.POST of_Start()

/* you'll notice that the window events ue_thread1 and ue_thread2 are fired concurrently */



end event

type st_2 from statictext within w_multithread
int X=1317
int Y=160
int Width=384
int Height=80
boolean Enabled=false
boolean Border=true
BorderStyle BorderStyle=StyleLowered!
string Text="0"
Alignment Alignment=Center!
boolean FocusRectangle=false
long TextColor=8388608
long BackColor=67108864
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type st_1 from statictext within w_multithread
int X=585
int Y=160
int Width=384
int Height=80
boolean Enabled=false
boolean Border=true
BorderStyle BorderStyle=StyleLowered!
string Text="0"
Alignment Alignment=Center!
boolean FocusRectangle=false
long TextColor=8388608
long BackColor=67108864
int TextSize=-8
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

WorldMobile 2004-12-16
  • 打赏
  • 举报
回复
3.nv_test

forward
global type nv_test from nonvisualobject
end type
end forward

global type nv_test from nonvisualobject
end type
global nv_test nv_test

type variables
nonvisualobject inv_arg
long il_count
end variables

forward prototypes
public function integer of_start ()
public function long of_getcount ()
public function integer of_setparent (nonvisualobject anv_arg)
end prototypes

public function integer of_start ();time t1

t1 = now()

do while secondsafter(t1,now()) < 5
il_Count++
inv_arg.triggerevent('ue_thread')
loop

return 1
end function

public function long of_getcount ();return il_count
end function

public function integer of_setparent (nonvisualobject anv_arg);inv_arg = anv_arg
return 1
end function

on nv_test.create
TriggerEvent( this, "constructor" )
end on

on nv_test.destroy
TriggerEvent( this, "destructor" )
end on

WorldMobile 2004-12-16
  • 打赏
  • 举报
回复
2.nv_arg2

forward
global type nv_arg2 from nonvisualobject
end type
end forward

global type nv_arg2 from nonvisualobject
event ue_thread ( )
end type
global nv_arg2 nv_arg2

type variables
window w
integer ii_thread
end variables

forward prototypes
public function integer of_setparent (window a)
end prototypes

event ue_thread;w.triggerevent('ue_thread2')
end event

public function integer of_setparent (window a);w = a
return 1
end function

on nv_arg2.create
TriggerEvent( this, "constructor" )
end on

on nv_arg2.destroy
TriggerEvent( this, "destructor" )
end on

WorldMobile 2004-12-16
  • 打赏
  • 举报
回复
给大家贴源代码,声明并非原创
一共有四个对象,nv_arg1、nv_arg2、nv_test、w_main
1.nv_arg1
forward
global type nv_arg1 from nonvisualobject
end type
end forward

global type nv_arg1 from nonvisualobject
event type long ue_thread ( )
end type
global nv_arg1 nv_arg1

type variables
window iw_parent

end variables

forward prototypes
public function integer of_setparent (window aw_parent)
end prototypes

event ue_thread;iw_Parent.Triggerevent('ue_thread1')
return 1
end event

public function integer of_setparent (window aw_parent);iw_Parent = aw_Parent
return 1
end function

on nv_arg1.create
TriggerEvent( this, "constructor" )
end on

on nv_arg1.destroy
TriggerEvent( this, "destructor" )
end on

mnsiii 2004-12-16
  • 打赏
  • 举报
回复
SharedObjectRegister('uo_thread','object1')
//将uo_thread对象注册为object1
SharedObjectRegister('uo_thread','object2')
//将uo_thread对象注册为object2

SharedObjectGet('object1',uo_thread1)
//用uo_thread1引用共享对象object1
SharedObjectGet('object2',uo_thread2)
//用uo_thread2引用共享对象object2


uo_thread1.uf_setparent(uo_arg1) //用中间对象给uo_thread1中的实例变量赋值
uo_thread2.uf_setparent(uo_arg2)

uo_thread1.Post uf_start() //利用服务器推送技术,异步调用共享对象中的uf_start()
uo_thread2.Post uf_start()//相当于启动线程


这是一个小例子,你可能看不明白,不过楼上的那篇文章应该不错。这个主要就是一个post函数
balloonman2002 2004-12-16
  • 打赏
  • 举报
回复
http://www.pdriver.com/display.asp?key_id=1059&ai_down=1
WorldMobile 2004-12-16
  • 打赏
  • 举报
回复
呵呵,chen_pb (倒霉) 兄,用post来实现即可

1,076

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧