PowerTCP Sockets for .NET
Start Method (Tcp)
Example 




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

Parameters

worker
System.Threading.WaitCallback delegate specifying the function to execute.
state
Information to pass to the worker delegate method; can be null.
Remarks

This method provides an easy means for executing blocking functions on a worker thread. Applications with a UI thread should use this technique to execute processes (like Connect and Read) that can block the UI thread.

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

Example
The following example demonstrates simple Tcp read and write operations on a worker thread, and marshaling the received data to the main thread.
private void button1_Click(object sender, EventArgs e)
{
    tcp1.Start(connectWriteRead, null);
}

private void connectWriteRead(object state)
{
    tcp1.Connect(new TcpSession(new Dart.Sockets.IPEndPoint(myEchoServer, 7)));
    tcp1.Write("hello world!");
    byte[] buffer = new byte[128];
    tcp1.Marshal(tcp1.Read(buffer), "", null);
    tcp1.Close();
}

void tcp1_Data(object sender, Dart.Sockets.DataEventArgs e)
{
    textBox1.AppendText(e.Data.ToString());
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    tcp1.Start(AddressOf connectWriteRead, Nothing)
End Sub

Private Sub connectWriteRead(ByVal state As Object)
    tcp1.Connect(New TcpSession(New Dart.Sockets.IPEndPoint(myEchoServer, 7)))
    tcp1.Write("hello world!")
    Dim buffer(127) As Byte
    tcp1.Marshal(tcp1.Read(buffer), "", Nothing)
    tcp1.Close()
End Sub

Private Sub tcp1_Data(ByVal sender As Object, ByVal e As Dart.Sockets.DataEventArgs)
    textBox1.AppendText(e.Data.ToString())
End Sub
See Also

Reference

Tcp Class
Tcp Members


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