Ik wil graag onderstaande voorbeeldcode uit MSDN uitbreiden met een timer die de code elke minuut aftrapt. Wie kan en wil me helpen?
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| Imports System.Net.NetworkInformation Imports System.Globalization Imports System.ComponentModel Imports System Imports System.Windows.Forms Public Class PingClientForm Dim WithEvents pingClient As New Ping() Private Sub pingClient_PingCompleted( _ ByVal sender As Object, ByVal e As PingCompletedEventArgs) _ Handles pingClient.PingCompleted ' Check to see if an error occurred. If no error, then display the ' address used and the ping time in milliseconds If e.Error Is Nothing Then If e.Cancelled Then pingDetailsTextBox.Text &= _ "Ping cancelled." & Environment.NewLine Else If e.Reply.Status = IPStatus.Success Then pingDetailsTextBox.Text &= _ " " & e.Reply.Address.ToString() & " " & _ e.Reply.RoundtripTime.ToString( _ NumberFormatInfo.CurrentInfo) & "ms " & _ Environment.NewLine Else pingDetailsTextBox.Text &= _ " " & GetStatusString(e.Reply.Status) & _ Environment.NewLine End If End If Else ' Otherwise display the error pingDetailsTextBox.Text &= _ " Ping error." & Environment.NewLine MessageBox.Show( _ "An error occurred while sending this ping. " & _ e.Error.InnerException.Message.ToString()) End If sendPingButton.Enabled = True End Sub Private Function GetStatusString(ByVal status As IPStatus) As String Select Case status Case IPStatus.Success Return "Success." Case IPStatus.DestinationHostUnreachable Return "Destination host unreachable." Case IPStatus.DestinationNetworkUnreachable Return "Destination network unreachable." Case IPStatus.DestinationPortUnreachable Return "Destination port unreachable." Case IPStatus.DestinationProtocolUnreachable Return "Destination protocol unreachable." Case IPStatus.PacketTooBig Return "Packet too big." Case IPStatus.TtlExpired Return "TTL expired." Case IPStatus.ParameterProblem Return "Parameter problem." Case IPStatus.SourceQuench Return "Source quench." Case IPStatus.TimedOut Return "Timed out." Case Else Return "Ping failed." End Select End Function Private Sub sendPingButton_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendPingButton.Click addressTextBox.SelectAll() If addressTextBox.Text.Length <> 0 Then ' Disable the Send button. sendPingButton.Enabled = False pingDetailsTextBox.Text &= _ "Pinging " & addressTextBox.Text & _ " . . ." & Environment.NewLine ' Send ping request pingClient.SendAsync(addressTextBox.Text, Nothing) Else MessageBox.Show("Please enter an IP address or host name.") End If sendPingButton.Update() End Sub Private Sub cancelPingButton_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelPingButton.Click ' Cancel any pending pings. pingClient.SendAsyncCancel() End Sub End Class |
[ Voor 0% gewijzigd door RobIII op 20-03-2007 22:43 . Reden: Code tags ]