C# .net - Ping method

2008-06-10 4:08 pm
我有一個 XML file, 裡面有一堆 IP addresses. 我現在要做既係要用 C# 寫個 program 要每30分鐘去 ping() 哩一堆 IP addresses 來 check 下邊條 link 死左。

我現在做既方法係用個 loop 續個續個 IP 去 pink()。但發覺太徙時間,而且當有好多 IP address時,就變左唔係每個 IP 可以向 30分鐘 check到有冇死。

所以我想問係 C# 會唔會有任何方法或 method 可以係同一時間去 ping() 晒哩堆 IP addresses.

Thanks

回答 (3)

2008-06-11 6:05 pm
✔ 最佳答案
The problem is that “ping” will block and wait for server respond by using ICMP Protocol. If the server does not respond, ping will wait until timeout, the wait time can be as long as a few minutes for each check.

If you are using Send try “SendAsync”. Each SendAsync will create a thread on its own, so your program does not need to wait for rely from each site one by one!!
From MSDN
The Ping class offers both synchronous and asynchronous methods for sending the request. If your application should block while waiting for a reply, use the Send methods; these methods are synchronous. If your application should not block,use the asynchronous SendAsync methods. A call to SendAsync executes in its own thread that is automatically allocated from the threadpool. When the asynchronous operation completes, it raises the PingCompleted event. Applications use a PingCompletedEventHandler delegate to specify the method that is called for PingCompleted events. You must add a PingCompletedEventHandler delegate to the event before calling SendAsync.The delegate's method receives a PingCompletedEventArgs object that contains a PingReply object that describes the result of the SendAsync call.
You cannot use the same instance of the Ping class to generate multiple simultaneous ICMP Echo requests. Calling Sendwhile a SendAsync call is in progress or calling SendAsync multiple times before all previous calls have completed causes an InvalidOperationException.
2008-06-11 6:55 am
你好,我推薦你一個關于 Xanga 基本語法教學的網站,他包括許多 Xanga 的小技巧, Xanga Skin, Xanga Script.

http://www.xanga-help.com

希望這個網站對你有參考價值。

祝你好運!
2008-06-10 5:50 pm


收錄日期: 2021-04-29 17:23:35
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080610000051KK00387

檢視 Wayback Machine 備份