TC官方合作论坛
标题:
线程交互
[打印本页]
作者:
B哥
时间:
2012-12-17 00:06
标题:
线程交互
大家写脚本,经常会被验证码、死亡等突然发生的问题卡死脚本有木有?有木有? 反正我是。所以今天特意使用线程来解决这个问题。。因为线程他可以随时处理这些问题。。。。 1.准备三条线程:人物操作跑图线程、死亡处理线程、验证处理线程。
2. 人物操作跑图线程级别最低,验证处理线程可以暂停,恢复。死亡处理线程可以关闭和重开。上代码吧。
namespace TIT
//TIT 看不懂是啥意思吧?是这个意思ThreadInteractiveTest..TC不让我用!
int handle //控制线程事件句柄 --------个人认为其实就是一个临界区一把钥匙
int runChartThreadhandle //跑图线程句柄
int deathThreadhandle //死亡线程句柄
int checkCodeThreadhandle //验证码句柄
//启动所有线程
function bool startThread(string str)
//创建一个带名字的事件,自动设置事件状态,初始事件可用
handle=thread.createevent(false,true,"event")
//---------启动下面所有线程
runChartThreadhandle = thread.beginthreadex("TIT.runChart","","TIT.cancellationRunChart","")
checkCodeThreadhandle = thread.beginthreadex("TIT.checkCode","","TIT.cancellationCheckCode","")
deathThreadhandle = thread.beginthreadex("TIT.death","","TIT.cancellationDeath","")
help.sleep(10000)
thread.closethread(runChartThreadhandle)
return true
endfunction
//游戏人物路图线程
function bool runChart(string str)
help.messagebox("跑图线程被开始了!!!!!!!!!!!!!!!!")
while(true)
help.sleep(3000)
help.messagebox("角色在跑图中...")
endwhile
return true
endfunction
//人物路图线程线程结束要做的操作
function bool cancellationRunChart(string str)
help.messagebox("跑图线程被关闭")
return true
endfunction
//验证码线程
function bool checkCode(string str)
while(true)
help.sleep(12000)
thread.waitforthread(handle,-1)//发现死亡无限等待,其它操作事件被占用
bool a = thread.suspendthread(runChartThreadhandle)
//if(!a)
//help.messagebox("线程暂停失败")
//endif
help.messagebox("发现验证码载图,其它线程给我停会----")
help.sleep(10000)
bool b = thread.resumethread(runChartThreadhandle)
//if(!a)
//help.messagebox("线程恢复失败")
//endif
help.messagebox("验证码载图发送完毕,你们先上一会-----")
thread.setevent(handle)//复活后,其它事件为可用状态
help.sleep(9000)
thread.waitforthread(handle,-1)//发现死亡无限等待,其它操作事件被占用
thread.suspendthread(runChartThreadhandle)
help.messagebox("我的码有回应了,你们停下,输入验证码...")
help.sleep(10000)
help.messagebox("输入完了,警察走了,哎又交了几分钱保护费。你们搞...")
thread.resumethread(runChartThreadhandle)
thread.setevent(handle)//复活后,其它事件为可用状态
endwhile
return true
endfunction
//验证码线程结束要做的操作
function bool cancellationCheckCode(string str)
help.messagebox("验证码线程被关闭")
return true
endfunction
//死亡线程
function bool death(string str)
while(true)
help.sleep(18000)//发现死亡
thread.waitforthread(handle,-1)//发现死亡无限等待,其它操作事件被占用
thread.closethread(runChartThreadhandle)//你丫的还跑个毛呀,都是尸体了。
//---------------------------------------------这里关闭跑图子线程。所有程序全关闭。
//----------有人告诉我这是为什么,还是本身就不能这样干?
help.messagebox("春哥正在复活中...")
help.sleep(2000)
//跑图线程被重新开始
runChartThreadhandle = thread.beginthreadex("TIT.runChart","","TIT.cancellationRunChart","")
thread.setevent(handle)//复活后,其它事件为可用状态
endwhile
return true
endfunction
//死亡线程结束要做的操作
function bool cancellationDeath(string str)
help.messagebox("死亡线程被关闭")
return true
endfunction
//开始按钮事件
function bool start_click()
TIT.startThread("")
return true
endfunction
//结束按钮事件
function bool exit_click()
thread.closethread(runChartThreadhandle)
thread.closethread(deathThreadhandle)
thread.closethread(checkCodeThreadhandle)
thread.closehandle(handle)//清理内核对象,释放资源
help.exit()
return true
endfunction
endnamespace
复制代码
这只是我个人想法。测试结果差不多也能看出效果了!如果有大神有更好的思路,请多多训导。。。
注:::大家以后取空间名不要太专业了。如:ThreadInteractiveTest、CloseThreadTest 这些被 TC 内部占用的空间名。。。。当运行时。啥也不说,直接关闭TC主程序。你会付出惨痛的代价的。信不信由你。反正我流血了!!!
作者:
zzj15895781288
时间:
2012-12-17 00:09
沙发
作者:
B哥
时间:
2012-12-17 00:10
回复
2楼
zzj15895781288
的帖子
师父来了。。欢迎,欢迎...
作者:
冷月无痕
时间:
2012-12-17 08:49
英文的没用过,表示用 线程关闭测试 线程开启测试 这些无压力
欢迎光临 TC官方合作论坛 (http://bbs.52tc.co/)
Powered by Discuz! X3.1