dbasnett

A couple of things that have me at wits end. I have an application that has the following problems / concerns:

1. When my application is running and the system attempts shutdown / restart / logoff my app closes, but the system doesn't perform the action. When I look at the Windows Task Manager I see that a large number of the normally running task have been killed as expected. I have tried my app with and without seesionending event handler.

2. My app displays battery status.
Dim bST as String
Dim ps As PowerStatus = SystemInformation.PowerStatus
bST = ps.BatteryChargeStatus.ToString
I expected bST to contain High, Low, Critical, etc. But it appears that one of the states is "0".

3. ping www.yahoo.com
Ping request could not find host www.yahoo.com. Please check the name and try again.

This is an ongoing gripe, that has the same result when using
Dns.GetHostEntry(anAddr)

The error is incorrect mostly. Yes it couldn't find it, but it couldn't find it because the DNS server was down.
Ping request could not find host www.yahoo.com
is different than
Ping request could not find host www.yahoo.com because DNS server did not respond

After sniffing more packets than I care to remember it seems obvious that the OS knows the difference between a DNS server responding host unknown and DNS server not responding at all, but it all seems the same.

4. Why does this have to throw an exception

pingReply.Address.ToString

It is legitimate that the address may be nothing, but why when casting nothing to string do you get an exception instead of a null string.



Re: Visual Basic General VB2005 Issues

kleinma

1) Is this when running a release mode compiled exe or when running in the IDE Are you sure your app is the culprit (i.e. you have confirmed this behavior ONLY occurs when your app is running and you shut down the OS)

2) Never used those properties before, but I know that the BatteryChargeStatus property can be a bitwise combination (i.e. the status could be BatteryChargeStatus.Charging and also BatteryChargeStatus.Low)

So perhaps when you are getting 0, it could be because you are calling .ToString when it is in one of these bitwise combination states. Again this is just an educated guess.

3) Not sure why your yahoo pings arent working... All 3 of these pieces of code produce valid results.

Code Snippet

MsgBox(My.Computer.Network.Ping("www.yahoo.com"))

Dim MyPing As New System.Net.NetworkInformation.Ping

Dim MyPingResult As System.Net.NetworkInformation.PingReply = MyPing.Send("www.yahoo.com")

MsgBox(MyPingResult.RoundtripTime)

MsgBox(System.Net.Dns.GetHostEntry("www.yahoo.com").AddressList(0).ToString())

4) The exception is likely because for whatever reason (can't tell without seeing your code), either pingReply itself, or pingReply.Address is equal to nothing (aka null).

When you go to call .ToString on it, it accesses the object itself before it calls its .ToString method. So if the object is nothing, you get an error.






Re: Visual Basic General VB2005 Issues

dbasnett

1. Happens when running the compiled exe. It does appear to only happen when my app is running. FYI - I do cancel the close event, do a little cleanup, and then exit the application. I have removed the sessionending event handler.

2. Good insight. I think I checked this before and the value was zero, but I'll check again.

3. Sorry about the confusion. yahoo pings fine. The point I was trying to make was that you can get a host not found message for several reasons:

a. the host name is not valid

b. your connection to the DNS server is down

c. the DNS server is down

From looking at a lot of packet captures I can discern when it is a. It is b & c I have a problem with. It is just a shame that the OS doesn't make it obvious, especially when it knows the distinction.

Ping request could not find host www.foo.com
is different than
Ping request could not find host www.foo.com because DNS server did not respond

4. I had a feeling that was the answer.






Re: Visual Basic General VB2005 Issues

kleinma

You can get all the information you want. You just need to know where to look.

If a ping request fails, an exception is thrown. The exception by itself doesn't tell you much, but if its a pingexception that occurs, and the innerexception is a socketexception, then the ping request failed for a specific reason that can be queried.

Here is some sample code to illustrate.

Code Snippet

Dim MyPing As New System.Net.NetworkInformation.Ping

Dim MyReply As System.Net.NetworkInformation.PingReply = Nothing

Try

'PING SOME DOMAIN

MyReply = MyPing.Send("www.blahblahblahblahblahblahblah.com")

'IF NO ERROR WAS THROWN, DISPLAY ROUNDTRIP TIME

MessageBox.Show(MyReply.RoundtripTime.ToString)

Catch ex As System.Net.NetworkInformation.PingException

'IF PING EXCEPTION OCCURS LOOK AT INNER EXCEPTION

If TypeOf ex.InnerException Is System.Net.Sockets.SocketException Then

'WHEN INNER EXCEPTION IS SOCKET EXCEPTION, WE CAN LOOK AT THE

'REASON WHY BY CASTING IT TO THE CORRECT EXCEPTION TYPE

'AND LOOKING AT ITS SOCKET ERROR CODE

Select Case DirectCast(ex.InnerException, System.Net.Sockets.SocketException).SocketErrorCode

Case Net.Sockets.SocketError.HostNotFound

Case Net.Sockets.SocketError.HostDown

Case Net.Sockets.SocketError.HostUnreachable

Case Net.Sockets.SocketError.AccessDenied

Case Net.Sockets.SocketError.TimedOut

'ETC, ETC ETC, THERE ARE MANY SOCKET ERROR CODES PREDEFINED IN THE FRAMEWORK FOR YOU

End Select

Else

'OTHERWISE SHOW MESSAGE FOR ERROR (NOT A SOCKET ERROR)

MessageBox.Show(ex.Message)

End If

End Try






Re: Visual Basic General VB2005 Issues

dbasnett

I'll take a look at the inner exception.

Any ideas on my close problem

Update on the power status. It is not a combination of other states. It is 0, which does not have a definition, at least not one I can find.






Re: Visual Basic General VB2005 Issues

dbasnett

I was using command line ping as an example. What I am doing in code is

Dns.GetHostEntry("www.blahblahblahblahblahblahblah.com")

If the exception is thrown it doesn't matter if the name is invalid, the internet connection is down, or the dns server is down, I always get socket.error.hostnotfound.

I am trying to distinguish between whether the name is really bad or I just can't get to the dns server / dns server down. The same sort of behavior happens in Internet Explorer.

The point of all of this, I am trying to finish up a Network utility. In the process of writing it I discovered instantances where I could get to the internet if I knew the IP address, but names would not resolve, hence my quest.

Thanks for all of your help.






Re: Visual Basic General VB2005 Issues

kleinma

I was able to reproduce your battery status issue. I entered it as a bug so we will see what kind of response comes back.




Re: Visual Basic General VB2005 Issues

dbasnett

Thanks. I had entered the problem here also

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1526963&SiteID=1






Re: Visual Basic General VB2005 Issues

kleinma

dbasnett,

What OS are you running when you experience the 0 value for battery status






Re: Visual Basic General VB2005 Issues

dbasnett

XP Prof. SP2

Beleive OS is currently up to date.






Re: Visual Basic General VB2005 Issues

kleinma

What type of laptop

Only reason I am asking, is Microsoft said they could not reproduce the issue.

I was able to using Vista that is on an HP dv6000 laptop.






Re: Visual Basic General VB2005 Issues

dbasnett

Dell Inspiron 9200.

Didn't you say that you created the problem I wonder if MS actually waited for it. Like I said, on my computer it happens between High and Low states, around 55% remaining.






Re: Visual Basic General VB2005 Issues

kleinma

Yes I was able to, but Microsoft said they could not when they tested out.

You can check the connect bug here

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx FeedbackID=273815

I gave them instructions on how to reproduce.