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. Managed C++/CLI
  4. How to check availability of internet connection

How to check availability of internet connection

Scheduled Pinned Locked Moved Managed C++/CLI
databasesysadminmysqljsontutorial
6 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.
  • A Offline
    A Offline
    anveshvm
    wrote on last edited by
    #1

    Hi I have an SQL query which is to be executed from the server. Just before executing, I am checking if the internet is available or not. I am using InternetGetConnectedState api to implement this. But this call returns true, for 2-3 seconds after the network connection is lost. This causes the application to hang. Pls verify my code and check if it is the appropriate code --------------------------------------------------- [DllImport("wininet.dll", SetLastError=true,CharSet=CharSet::Unicode,ExactSpelling=true, CallingConvention=CallingConvention::StdCall)] static bool InternetGetConnectedState(int &Description, int ReservedValue ) ; bool IsConnectedToInternet() { int Desc ; return InternetGetConnectedState(Desc, 0 ) ; } if (IsConnectedToInternet()) { mysql_query(mysqlConnectorObject,sqlQuery); return mysql_store_result(mysqlConnectorObject); } else { MessageBox::Show("Not connected"); } ---------------------------------------------------- Thanks in advance Anvesh

    L 1 Reply Last reply
    0
    • A anveshvm

      Hi I have an SQL query which is to be executed from the server. Just before executing, I am checking if the internet is available or not. I am using InternetGetConnectedState api to implement this. But this call returns true, for 2-3 seconds after the network connection is lost. This causes the application to hang. Pls verify my code and check if it is the appropriate code --------------------------------------------------- [DllImport("wininet.dll", SetLastError=true,CharSet=CharSet::Unicode,ExactSpelling=true, CallingConvention=CallingConvention::StdCall)] static bool InternetGetConnectedState(int &Description, int ReservedValue ) ; bool IsConnectedToInternet() { int Desc ; return InternetGetConnectedState(Desc, 0 ) ; } if (IsConnectedToInternet()) { mysql_query(mysqlConnectorObject,sqlQuery); return mysql_store_result(mysqlConnectorObject); } else { MessageBox::Show("Not connected"); } ---------------------------------------------------- Thanks in advance Anvesh

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, InternetGetConnectedState() is the best way I know to look at the Internet connection state. You are saying it shows a slightly outdated state, but that should not be too bad. Anyway, the connection could be lost right after you call the function, so the code that follows must survive that anyway. Hence, use asynchronous code (on a separate thread) and give whatever you are trying to do a timeout. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Fixturized forever. :confused:


      A 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, InternetGetConnectedState() is the best way I know to look at the Internet connection state. You are saying it shows a slightly outdated state, but that should not be too bad. Anyway, the connection could be lost right after you call the function, so the code that follows must survive that anyway. Hence, use asynchronous code (on a separate thread) and give whatever you are trying to do a timeout. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Fixturized forever. :confused:


        A Offline
        A Offline
        anveshvm
        wrote on last edited by
        #3

        Thank you very much..... Can you pls tell me how to set the time limit when starting a new thread. Can you also suggest the most suited class to do this? I mean whether it is backgroundworker, threadpool or thread class?

        L A 2 Replies Last reply
        0
        • A anveshvm

          Thank you very much..... Can you pls tell me how to set the time limit when starting a new thread. Can you also suggest the most suited class to do this? I mean whether it is backgroundworker, threadpool or thread class?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          anveshvm wrote:

          how to set the time limit

          you either perform calls that support a time limit, or you should launch a (one-shot) timer, which: - you cancel again when the operation succeeds - and if the timer fires, you stop the timer and cancel the thread

          anveshvm wrote:

          backgroundworker, threadpool or thread?

          whatever fits your circumstances best; since you may have to abort it, threadpool could not be the right choice though. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Fixturized forever. :confused:


          1 Reply Last reply
          0
          • A anveshvm

            Thank you very much..... Can you pls tell me how to set the time limit when starting a new thread. Can you also suggest the most suited class to do this? I mean whether it is backgroundworker, threadpool or thread class?

            A Offline
            A Offline
            anveshvm
            wrote on last edited by
            #5

            Thank you Luc Pattyn.... I will try that way. :)

            L 1 Reply Last reply
            0
            • A anveshvm

              Thank you Luc Pattyn.... I will try that way. :)

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, I just discovered this article[^] that may interest you. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Fixturized forever. :confused:


              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