473,378 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Check Internet Connection

Tyler Wiebe
I'm currently making an application that will display a notification when I receive a new email in my gmail account, and that works fine, but if my internet connection gets disconnected while it's checking if I have any new messages, it'll get an error at whatever spot it's at in the code.

I've purposefully disconnected it numerous times, and I've gotten an error at about 5 different places in the code when ever I disconnect from the internet. I'm wondering, is it possible to fix this? Maybe a try, catch, so that if an error does occur, in the catch, it'll check if there's an internet connection, and if there is a connection, it'll display the error, and if there is no connection, it'll just blame that to be the cause and ignore it.

I know that's not efficient, so any help is much appreciated.
Sep 6 '11 #1
1 2369
GaryTexmo
1,501 Expert 1GB
The thing with a network connection is that even if you establish that it works before you start your code, you could lose it at any time. I would recommend encapsulating the whole thing inside a try/catch (which you should probably do already if you haven't yet) and then consider using sub try/catch blocks inside that to further refine your error reporting.

You could also consider having your program operate as a state machine, that way if you do lose your connection you can quickly return to the last successful state when the connection works again. If it's lost, you can enter a state that attempts to reconnect using a Timer at set intervals. Make sure you make the interval long enough so that you aren't stacking up on your timeouts, or only allow one attempt at a time... that kind of thing.

I hope that helps... good luck!
Sep 6 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kadir CAMOGLU | last post by:
Hi all, I am writing a program with vb.net which getting some information from internet. I must check internet connection before some prosess. But how?
6
by: Matt Hawley | last post by:
I'm facing a problem where I need to verify that my windows forms application has access to the internet before it can do anything. Currently, the only way I can think of is by creating a...
0
by: sleepyant | last post by:
Hi, how can I check the internet connection and pop-up a Dial-Up Networking dialog when there isn't any? I've tried the following: Dim myReq As HttpWebRequest Try myReq =...
9
by: sleepyant | last post by:
Hi, I've posted this question on several forum but have no response. So I hope anyone who have any idea what I'm talking about please give your solution or advice. My problem is I need to check...
8
by: Jozef | last post by:
Hello, Is there a way to test that an internet connection exists and that you are able to see the webserver before performing any connections? The reason being, when I try to connect to an SQL...
3
by: Jonny | last post by:
Hi, Please could you tell me how to check for an internet connection in C. I'm using Windows 2000. Many Thanks, Jonny
2
by: Ron Vecchi | last post by:
I have an aplication that will consitently be comutication with a webserver remotly via Internet. What is the best way and most lightweight way to constently check the conection so my app will...
8
by: Nikola Bucic | last post by:
Could someone tell me how can I constantly check if I'm connected to internet and if possible to determine what type of connection is it. My best shot wright now is to have a timer which will...
4
by: Goldwind | last post by:
Hi, From a desktop application, i want to check if an internet connection exist. Many articles use the win api "InternetGetConnectedState", but it is no sure thing. I can check it by calling a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.