Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Network System.Net.Dns.GetHostByAddress is too slow

Network System.Net.Dns.GetHostByAddress is too slow

Scheduled Pinned Locked Moved C#
helpcsharpsysadminperformancequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bradsnobar
    wrote on last edited by
    #1

    Hello, I have an app that I use to get poll for the hostnames on my local network. I use this method to get the information. System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostByAddress(address); The problem is that when GetHostByAddress(...) fails because there is no machine at a given IP address, it throws an exception that takes a long time (a few seconds). Is there a faster method to call? Is there a method that does the same thing, but sets an error value instead of throws an exception when a bad thing occurs? Is there some kind of timeout setting that I can set to like 20 milliseconds? (I can be assured of always being on a lan with a fast response) I use a whole bunch of threads to speed up the application, which makes the wait more tolerable, but it still takes way too long for my taste. Is there a better method to use in .Net 2.0 Thanks.

    L 1 Reply Last reply
    0
    • B bradsnobar

      Hello, I have an app that I use to get poll for the hostnames on my local network. I use this method to get the information. System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostByAddress(address); The problem is that when GetHostByAddress(...) fails because there is no machine at a given IP address, it throws an exception that takes a long time (a few seconds). Is there a faster method to call? Is there a method that does the same thing, but sets an error value instead of throws an exception when a bad thing occurs? Is there some kind of timeout setting that I can set to like 20 milliseconds? (I can be assured of always being on a lan with a fast response) I use a whole bunch of threads to speed up the application, which makes the wait more tolerable, but it still takes way too long for my taste. Is there a better method to use in .Net 2.0 Thanks.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use the asynchronous BeginGetHostEntry method, it will not block. (You can also use BeginGetHostByName, but it's marked as obsolete in .NET 2.0) regards

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups