事件处理 [英] event handeling

查看:65
本文介绍了事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我写了一个程序来ping一系列IP.当我获得IP时,我使用了for循环来ping通所有IP,但是由于它尝试ping通第二个IP而第一个仍然无法ping答复,因此会导致错误.然后我尝试通过监视来使用pingCompelet_eventhandler来解决此问题,但我发现首先执行了所有for循环,然后将其输入到pingCompelet_eventhandler!所以我不知道如何确定ping操作是否完成,如果您能帮助我,我将不胜感激.
值得一提的是,我设法通过thread.sleep(7000)解决了这个问题;但是它使程序非常慢.请帮帮我.
tnx

解决方案

,您可以创建一个信号量,并使用它在循环中等待,直到pingCompelete事件释放它为止.这样可以使其更安全,而且您不必依赖睡眠(使用睡眠非常糟糕!)

祝你好运!


hi i write a program that ping a range of IPs. when i get IPs ,i used a for loop to ping all IPs but it lead to error beacuse it try to ping second one while the first one still dont get ping reply. then i try to use pingCompelet_eventhandler to by monitoring solve this problem but i found that at first all of for loop executed and then it enter to pingCompelet_eventhandler! so i dont know how determine that at each step ping is compeletd, i''ll be gratefull if you can help me.
it''s good to mention that i manage to solve this problem by thread.sleep(7000); but it made the program very slow. please help me.
tnx

解决方案

you could create a semaphore and use it to wait in the loop until the pingCompelete event releases it. This will make it more safe and you''re not depending on a sleep (using a sleep is very bad!)

Good luck!


这篇关于事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆