Click here to Skip to main content
15,895,606 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHelp regarding Serial Port in .NET 2005 Pin
yrsoft12-Mar-07 20:43
yrsoft12-Mar-07 20:43 
AnswerRe: Help regarding Serial Port in .NET 2005 Pin
TwoFaced12-Mar-07 21:20
TwoFaced12-Mar-07 21:20 
QuestionDatagrid Using Combobox and textbox and Automatically ComboBox and Datagrid Column also has to come pls Tell me... Pin
somagunasekaran12-Mar-07 19:20
somagunasekaran12-Mar-07 19:20 
QuestionSqlHelper Class Pin
cst_cfit12-Mar-07 18:23
cst_cfit12-Mar-07 18:23 
QuestionData Grid Selection Pin
umesh896512-Mar-07 17:59
umesh896512-Mar-07 17:59 
QuestionApplication Slowdown Question Pin
tgebrael12-Mar-07 17:57
tgebrael12-Mar-07 17:57 
AnswerRe: Application Slowdown Question Pin
tgebrael12-Mar-07 18:01
tgebrael12-Mar-07 18:01 
AnswerRe: Application Slowdown Question Pin
TwoFaced12-Mar-07 18:52
TwoFaced12-Mar-07 18:52 
Well I think your function could be cleaned up a little bit. First of all it seems to me it should return a boolean value instead of a string. Secondly this next line of yours is pretty useless:

tgebrael wrote:
If Not My.Computer.Network.Ping("www.google.com") Then GoTo TryNext


All this does is test if the ping succeeds and if it doesn't it skips to the next line. Skipping to the next line is unnecessary as your code would do that anyway without the goto statment. Also if it succeeds it again moves onto the next line and will execute the second method. So no matter what your function is trying both methods. This is one reason why you might find it slow. Instead of goto TryNext how about you just return "Available" or True if you decide to change it.

Also in every exception you have the same code. How about you move that code below the try catch block. It's just redundent. How about this:

Private Function isConnected() As Boolean
    Try
        'If ping succeed return
        If My.Computer.Network.Ping("www.google.com") Then Return True

        Dim AddressLength As IPHostEntry
        AddressLength = System.Net.Dns.GetHostEntry("google.com")

        'If lookup succeed return
        If AddressLength.AddressList.Length.Equals(3) Then Return True
    Catch Except As System.Net.Sockets.SocketException
        'Catch exception
    Catch Except As InvalidOperationException
        'Catch exception
    End Try

    'If we got this far attempts failed.  Return false
    Return False
End Function
If you still want to return a string you could modify it back to how you had it.

Also if you'd like to use the backgroundworker try it out. It's pretty easy to use. I'm sure you can find info online about it. It has a DoWork event which fires when you call the method 'RunWorkerAsync'. The code in this event runs asyncronosly. So all you'd have to do is in the DoWork event call your function get the value and then pass it back to the main thread. There is a RunWorkerCompleted event which fires when the task is completed. You can pass the result on to it and then do whatever you want with the value.
GeneralRe: Application Slowdown Question Pin
tgebrael12-Mar-07 21:47
tgebrael12-Mar-07 21:47 
QuestionNumber of sundays in a month.......... Pin
Member 387988112-Mar-07 17:50
Member 387988112-Mar-07 17:50 
AnswerRe: Number of sundays in a month.......... [modified] Pin
TwoFaced12-Mar-07 20:38
TwoFaced12-Mar-07 20:38 
GeneralRe: Number of sundays in a month.......... [modified] Pin
Member 387988112-Mar-07 23:29
Member 387988112-Mar-07 23:29 
GeneralRe: Number of sundays in a month.......... Pin
Member 387988112-Mar-07 23:54
Member 387988112-Mar-07 23:54 
Questiontrying to develop a program to run an .bat file as admin Pin
cpltek12-Mar-07 12:01
cpltek12-Mar-07 12:01 
AnswerRe: trying to develop a program to run an .bat file as admin Pin
Dave Kreskowiak12-Mar-07 12:45
mveDave Kreskowiak12-Mar-07 12:45 
GeneralRe: trying to develop a program to run an .bat file as admin Pin
cpltek13-Mar-07 3:05
cpltek13-Mar-07 3:05 
GeneralRe: trying to develop a program to run an .bat file as admin Pin
Dave Kreskowiak13-Mar-07 3:15
mveDave Kreskowiak13-Mar-07 3:15 
GeneralRe: trying to develop a program to run an .bat file as admin [modified] Pin
cpltek13-Mar-07 3:31
cpltek13-Mar-07 3:31 
GeneralRe: trying to develop a program to run an .bat file as admin Pin
cpltek13-Mar-07 3:38
cpltek13-Mar-07 3:38 
QuestionGet enter button command Pin
harveyhanson12-Mar-07 11:30
harveyhanson12-Mar-07 11:30 
AnswerRe: Get enter button command Pin
JUNEYT12-Mar-07 12:36
JUNEYT12-Mar-07 12:36 
GeneralRe: Get enter button command Pin
harveyhanson12-Mar-07 13:12
harveyhanson12-Mar-07 13:12 
GeneralRe: Get enter button command Pin
M-Hall12-Mar-07 14:44
M-Hall12-Mar-07 14:44 
GeneralRe: Get enter button command Pin
harveyhanson12-Mar-07 15:23
harveyhanson12-Mar-07 15:23 
QuestionCalling a windows application Pin
code123581312-Mar-07 10:47
code123581312-Mar-07 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.