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 in C#: how to detect that I have a break connection

Network in C#: how to detect that I have a break connection

Scheduled Pinned Locked Moved C#
csharpsysadmintutorialquestion
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.
  • Y Offline
    Y Offline
    youssef
    wrote on last edited by
    #1

    Hi, I would like to know in C# : how to detect that I have a break or connection with the network? Best Regards youssef

    H 1 Reply Last reply
    0
    • Y youssef

      Hi, I would like to know in C# : how to detect that I have a break or connection with the network? Best Regards youssef

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      As we've discussed in this board before, you should P/Invoke any one of various native functions like InternetCheckConnection:

      public bool Connected
      {
      get { return InternetCheckConnection("http://www.codeproject.com", 0, 0); }
      }
      [DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
      static extern bool InternetCheckConnection(string url, int flags, int reserved);

      You can also use this and similar functions defined in the WinInet library to force connections. Look-up that function in the MSDN Library[^] and you'll find more options with other similar functions. The pure .NET-way is just to request a network resource and handle SocketException or WebException (often times the SocketException is an inner-exception). This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      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