How to check availability of internet connection
-
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
-
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
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:
-
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:
-
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?
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:
-
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?
-
Hi, I just discovered this article[^] that may interest you. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused: