What is the best way to check for Internet connectivity using .NET?

后端 未结 27 2496
感动是毒
感动是毒 2020-11-22 07:41

What is the fastest and most efficient way to check for Internet connectivity in .NET?

27条回答
  •  佛祖请我去吃肉
    2020-11-22 08:40

    Instead of checking, just perform the action (web request, mail, ftp, etc.) and be prepared for the request to fail, which you have to do anyway, even if your check was successful.

    Consider the following:

    1 - check, and it is OK
    2 - start to perform action 
    3 - network goes down
    4 - action fails
    5 - lot of good your check did
    

    If the network is down your action will fail just as rapidly as a ping, etc.

    1 - start to perform action
    2 - if the net is down(or goes down) the action will fail
    

提交回复
热议问题