PowerTCP Emulation for .NET
Start Method (Rsh)
Example 




WaitCallback 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
Public Sub Start( _
   ByVal worker As WaitCallback, _
   ByVal state As Object _
) 
Dim instance As Rsh
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
WaitCallback delegate specifying the function to execute.
state
Information to pass to the worker delegate function; 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.

The state parameter can be null when no state information needs to be passed to the worker delegate function.

Unhandled exceptions thrown on the worker thread are reported by the Error event.

Example
This example demonstrates execution of a looping Read on a worker thread, and marshaling the data to the UI.
private void button1_Click(object sender, EventArgs e)
{
    //Receive data on a separate thread
    myComponent.Start(receiveData, null);
}

private void receiveData(object notUsed)
{
    //Receive data when it is sent by the remote host
    byte[] buffer = new byte[1024];
    while (myComponent.State != ConnectionState.Closed)
        myComponent.Marshal(myComponent.Read(buffer, 0, 1024), "", null);
}

private void myComponent_Data(object sender, DataEventArgs e)
{
    //Whenever data is received, display it
    textDisplay.AppendText(e.Data.ToString());
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Receive data on a separate thread
    myComponent.Start(AddressOf receiveData, Nothing)
End Sub

Private Sub receiveData(ByVal notUsed As Object)
    'Receive data when it is sent by the remote host
    Dim buffer() As Byte = New Byte(1023) {}
    Do While myComponent.State <> ConnectionState.Closed
        myComponent.Marshal(myComponent.Read(buffer, 0, 1024), "", Nothing)
    Loop
End Sub

Private Sub myComponent_Data(ByVal sender As Object, ByVal e As DataEventArgs) Handles myComponent.Data
    'Whenever data is received, display it
    textDisplay.AppendText(e.Data.ToString())
End Sub
See Also

Reference

Rsh Class
Rsh Members


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