I have this code that will print and email results of pings. On my test pc, it works great, but on the production pc, it prints/emails multiple lines of the errors. I've tried re-publishing it and re-installing it and it's the same each time. The only thing I've changed from the time it worked correctly to now is making the ping loop 4 times for each entry. I've gone through the code several times and I can't figure out why it work differently on 2 pcs.
Do While sr.EndOfStream = False
'Read in a line from file
linecheck = sr.ReadLine
'Check that line read isn't empty string and that it contains 2 parts, otherwise discard
If ((linecheck = "") Or (linecheck.Contains(",") = False)) Then
Else
'If ok, split read line and put in entry
entry = linecheck.Split(",")
Dim Ping As Ping = New Ping
Dim PingReply As PingReply
success = 0
For t As Integer = 0 To 3
If entry(0) = "y" Then
PingReply = Ping.Send(entry(1), 2000)
'Set current activity on toolstrip and cause repaint
tssActivity.Text = "Current Task: Pinging " & entry(2) & ": " & entry(1)
tssActivity.Invalidate()
'Set result parts 1 & 2 to current ping entry
line(0) = entry(2) & ": "
line(1) = entry(1)
'Set result part 3 (line(2)) to ping if success, error message if failed
If PingReply.Status = IPStatus.Success Then
line(2) = PingReply.RoundtripTime.ToString
success += 1
Else
line(2) = PingReply.Status.ToString
errtemp = line(0) & Chr(13) & Chr(10) & line(1) & Chr(9) & Chr(9) & "Ping: " & line(2) & Chr(13) & Chr(10)
End If
End If
Ping.Dispose()
Next
End If
If success = 0 Then
errstring += errtemp
End If
'Set result string (line(3))
line(3) = line(0) & Chr(13) & Chr(10) & line(1) & Chr(9) & Chr(9) & "Ping: " & line(2) & Chr(13) & Chr(10)
rtbResult.Text += line(3)
'kill ping after used
rtbResult.Invalidate()
Me.Refresh()
Loop
The lines of code I've added are 12, 13, 25, 32, and 35-37, otherwise, the program is unchanged. Works correctly from the IDE but not from the exe.
The weirdest thing about it is, sometimes it duplicates the message 3 or 4 times, sometimes as much as 15 times on the same entry. Each duplication is on a new line. Is it possible that it's not disposing the ping and just pinging the same server on the next round?
Unfortunately I can't attach to the process because I'm using VB Express.