最近還在學(xué)習PB,有點(diǎn)郁悶,還是不太喜歡PB啊
上周五看了一下PB,感覺(jué)還簡(jiǎn)單。本來(lái)已經(jīng)動(dòng)手,但因為周五下午有事出去,所以拖到今天。。
PB的多線(xiàn)程用到的就幾個(gè)函數
SharedObjectRegister()
SharedObjectGet()
SharedObjectUnregister()
用SharedObjectRegister(Classname,Instancename) PB幫助文件是Classname和Instancename,即類(lèi)名和實(shí)例名。
用SharedObjectGet(instancename , objectinstance) 將實(shí)例名和具體的對象實(shí)例綁定,然后就可以通過(guò)對象實(shí)例POST 出發(fā)類(lèi)里預定義的過(guò)程或函數。比如在類(lèi)中預定義了uo_add函數,可以objectinstance.post uo_add
用SharedObjectUnregister(instancename) Unregisters a user object that was previously registered. 注銷(xiāo)掉用戶(hù)實(shí)例對象
eg.
1、定義一個(gè)nvo_multithread
添加add(int ai_n)函數
int li_i
int li_result = 0
sleep(5)
For li_i= 0 To ai_n
li_result+=li_i
Next
messagebox("",string(li_result))
2、定義一個(gè)窗口,在Instance Variables定義變量:nvo_multithread invo_thread
3、在Open事件中的代碼:
invo_thread = Create nvo_multithread
SharedObjectRegister ("nvo_multithread" ,"thread1" )
SharedObjectGet ("thread1" , invo_thread)
4、在Close事件中的代碼:
Destroy invo_thread
SharedObjectUnregister("thread1")
5、可以在一個(gè)按鈕的Click事件中調用:
int i
invo_thread.post add(i)
調用后,就可以異步執行了
注意點(diǎn):如果想要多個(gè)線(xiàn)程一起執行,就一定要多注冊幾個(gè)實(shí)例對象。即多執行幾次2、4步??梢杂脭到M來(lái)做。
比如我在Instance Variables定義成nvo_multithread invo_thead[5]
Open事件:For li_ii= 1 to 5
invo_th[li_ii] = Create nvo_multithread
SharedObjectRegister( "nvo_multithread" , "tthread" + string(li_ii) )
SharedObjectGet ("tthread" + string(li_ii) , invo_th[li_ii] )
Next
Close事件:For li_ii= 1 to 5
Destroy invo_th[li_ii]
SharedObjectUnregister("thread" + string(li_ii))
Next