PowerTCP Sockets for .NET
Start(PingThreadStart,Object) Method
Example 




PingThreadStart delegate specifying the function to execute.
Information to pass to the worker delegate function; can be null.
Starts a worker thread on which the specified delegate function executes.
Syntax
'Declaration
 
Public Overloads Sub Start( _
   ByVal worker As PingThreadStart, _
   ByVal state As Object _
) 
'Usage
 
Dim instance As Ping
Dim worker As PingThreadStart
Dim state As Object
 
instance.Start(worker, state)
public void Start( 
   PingThreadStart worker,
   object state
)
public: void Start( 
   PingThreadStart* worker,
   Object* state
) 
public:
void Start( 
   PingThreadStart^ worker,
   Object^ state
) 

Parameters

worker
PingThreadStart delegate specifying the function to execute.
state
Information to pass to the worker delegate function; can be null.
Remarks

This method provides a convenient means for executing blocking functions on a worker thread. Applications with a UI thread should use this technique to execute processes (like multiple Pings) that can block the UI thread.

The local IP interface defaults to IPAddress.Any and the Ping.Type defaults to Ping.Type.Raw.

Unhandled exceptions occurring on the worker thread will be caught and reported by the Error event.

Example
The following example demonstrates pinging a remote host.
private void button1_Click(object sender, EventArgs e)
{
    ping1.Start(pingWorker, HostNameOrAddressToPingTextbox.Text);
}

private void pingWorker(PingSlave slave, object state)
{
    ping1.Marshal(slave.GetEchoes(new Dart.Sockets.IPEndPoint(state.ToString(), 0).Address, null, 20, 5000, false));
}

void ping1_Echo(object sender, EchoEventArgs e)
{
    string results = "The following echoes were returned:\r\n";
    for (int i = 0; i < e.Echoes.Length; i++)
        results += e.Echoes[i].ToString() + "\r\n";
    textBox1.AppendText(results);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    ping1.Start(AddressOf pingWorker, HostNameOrAddressToPingTextbox.Text)
End Sub

Private Sub pingWorker(ByVal slave As PingSlave, ByVal state As Object)
    ping1.Marshal(slave.GetEchoes((New Dart.Sockets.IPEndPoint(state.ToString(), 0)).Address, Nothing, 20, 5000, False))
End Sub

Private Sub ping1_Echo(ByVal sender As Object, ByVal e As EchoEventArgs)
    Dim results As String = "The following echoes were returned:" & vbCrLf
    For i As Integer = 0 To e.Echoes.Length - 1
        results &= e.Echoes(i).ToString() & vbCrLf
    Next i
    textBox1.AppendText(results)
End Sub
See Also

Reference

Ping Class
Ping Members
Overload List


PowerTCP Sockets for .NET Documentation Version 4.5
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic