事件处理 [英] event handeling
本文介绍了事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
值得一提的是,我设法通过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屋!
查看全文