Dart.Emulation Namespace > Rsh Class : Start Method |
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 )
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.
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