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. Best Practice: Internet Connection?

Best Practice: Internet Connection?

Scheduled Pinned Locked Moved C#
testingbeta-testinghelpquestiondiscussion
6 Posts 4 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.
  • T Offline
    T Offline
    Troy G
    wrote on last edited by
    #1

    Hello all, I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation. What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar. Does this make any sense? Any help is greatly appreciated. :)Thanks, Troy G

    M V 2 Replies Last reply
    0
    • T Troy G

      Hello all, I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation. What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar. Does this make any sense? Any help is greatly appreciated. :)Thanks, Troy G

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      Yes, you have to check it in a timer or thread. Whats the problem with that? Mazy You're face to face, With the man who sold the world - David Bowie

      T 1 Reply Last reply
      0
      • M Mazdak

        Yes, you have to check it in a timer or thread. Whats the problem with that? Mazy You're face to face, With the man who sold the world - David Bowie

        T Offline
        T Offline
        Troy G
        wrote on last edited by
        #3

        Mazy, No problem. Just thought there may be something else I could do that would be easier on resources. Thanks for responding, Troy

        1 Reply Last reply
        0
        • T Troy G

          Hello all, I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation. What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar. Does this make any sense? Any help is greatly appreciated. :)Thanks, Troy G

          V Offline
          V Offline
          visiontec
          wrote on last edited by
          #4

          Hi there I have the same problem as yours but u have at least made a function to get yr work done. I couldnt even do that ! can u plz pass a copy of that function to me? Thanks VisionTec

          N T 2 Replies Last reply
          0
          • V visiontec

            Hi there I have the same problem as yours but u have at least made a function to get yr work done. I couldnt even do that ! can u plz pass a copy of that function to me? Thanks VisionTec

            N Offline
            N Offline
            Nick Parker
            wrote on last edited by
            #5

            visiontec wrote: can u plz pass a copy of that function to me? Just P/Invoke InternetGetConnectedState[^] and call it when your Tick event fires from your timer. - Nick Parker
              My Blog

            1 Reply Last reply
            0
            • V visiontec

              Hi there I have the same problem as yours but u have at least made a function to get yr work done. I couldnt even do that ! can u plz pass a copy of that function to me? Thanks VisionTec

              T Offline
              T Offline
              Troy G
              wrote on last edited by
              #6

              This is what I use, there are a bunch of them... //Creating the extern function... [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int Description, int ReservedValue); //Creating a function that uses the API function... public static bool IsConnectedToInternet() { int Desc ; return InternetGetConnectedState(out Desc, 0); }

              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