Results 1 to 6 of 6

Thread: problems using WebClient

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176

    problems using WebClient

    I made an update system for my app but the only problem is that the thing crashed when ur not connected to the internet. I did some searching on the VB board but all those examples just work for modem/LAN and non works if you have multiple Network cards in ur Comp. Is there something cool in .NET that solves this?

    I also tried to use try, catch endtry etc but they don't really help me cause the WebClient comonent just loops until it DLs the file, it's doesn't give up .
    JpEgy

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    yeah but how CAN i detect an internet connection then? I have multiplce network cards and none of the ways shown on the boards seem to work...
    JpEgy

  3. #3
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    use WMI to query the network adapters
    This is and example

    VB Code:
    1. dim query1 as new ManagementObjectSearcher("select ConnectionState from Win32_NetorkConnection")
    2.  
    3. dim queryColl as ManagementObjectCollection() = query1.Get()
    4.  
    5. string connectionState = ""
    6. dim   mo as new ManagementObject()
    7.  
    8. For Each mo In queryColl
    9.     connectionState = mo("ConnectionState").ToString()
    10. Next
    11.  
    12. Select Case connectionState
    13.       Case "Connected"
    14.                'do whatever
    15.        Case "Error"
    16.                'do whatever
    17.        Case "Paused"
    18.                'do whatever
    19.        Case "Disconnected"
    20.                'do whatever
    21.        Case "Connecting"
    22.               'do whatever
    23.        Case "Reconnecting"
    24.                'do  whatever
    25. End Select

    You have to import System.Management namespace and the System.Managment.dll
    Dont gain the world and lose your soul

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    my .NET doesn;t really like that code, it's full of errors...
    JpEgy

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Sorry I made a few mistakes, I am so used to the C# syntax, I forgot that I was doing the VB example

    Here is updated code without the select statement.

    VB Code:
    1. Dim query1 As New ManagementObjectSearcher("select connectionstate from Win32_NetworkConnection")
    2.  
    3.         Dim queryColl As ManagementObjectCollection
    4.  
    5.         queryColl = query1.Get()
    6.  
    7.  
    8.         Dim connectionState As String = ""
    9.  
    10.         Dim mo As New ManagementObject()
    11.  
    12.         For Each mo In queryColl
    13.  
    14.  
    15.             connectionState = mo("ConnectionState").ToString()
    16.         Next
    17.  
    18.         MessageBox.Show(connectionState)
    Last edited by DevGrp; Apr 2nd, 2002 at 05:41 PM.
    Dont gain the world and lose your soul

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    hmmm, the messagebox stays kinda empty....
    JpEgy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width